Solved

little help

Posted on 2002-07-28
5
192 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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…
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

930 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

13 Experts available now in Live!

Get 1:1 Help Now