Solved

little help

Posted on 2002-07-28
5
189 Views
Last Modified: 2010-04-01
Hi,

can anybody give me a hint
i have 2 vectors of strings, one is a list containing
some names sorted from the base object to the top
eg

object1
object2
object3
object4

object 2 extensd object 1, 3 extends 2 and so on

the next vector is allso filled with strings that
represent theese classes (user input). it must contain at least one (the top object eg object4) and may contain some more but they must be in correct order.
so the user can enter
object1
object4

or

object3
object4

but can not enter

object2
object1
object4

can you help me with some sorting algorythm on this example ???

thanx
0
Comment
Question by:kalosi
  • 3
5 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 400 total points
ID: 7183721
There's no need to use a sorting algorithm. just compare the user input if the vector is not empty:

#include <string>
#include <vector>

using namespace std;

//...

vector<string> myvec;
string user_input;

// read input

if ( !myvec.empty()) {

 if ( 0 > user_input.compare ( *(myvec.back())) {

  // user input is "less", therefore not allowed
 }
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 7184190
Sorry,

"just compare the user input if the vector is not empty:"

should read

"just compare the user input to the last element of the vector if the vector is not empty:"

0
 
LVL 86

Expert Comment

by:jkr
ID: 7188771
Do you need more help?
0
 
LVL 11

Expert Comment

by:griessh
ID: 7378503
Dear kalosi

I think you forgot this question. I will ask Community Support to close it unless you finalize it within 7 days. You can always request to keep this question open. But remember, experts can only help you if you provide feedback to their questions.
Unless there is objection or further activity,  I will suggest to accept

     "jkr"

comment(s) as an answer.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!
======
Werner
0
 
LVL 6

Expert Comment

by:Mindphaser
ID: 7420080
Force accepted

** Mindphaser - Community Support Moderator **
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now