[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

little help

Posted on 2002-07-28
5
Medium Priority
?
215 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Enroll in October's Free Course of the Month

Do you work with and analyze data? Enroll in October's Course of the Month for 7+ hours of SQL training, allowing you to quickly and efficiently store or retrieve data. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

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 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.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

650 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