[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

little help

Posted on 2002-07-28
5
Medium Priority
?
218 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 1600 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

873 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