Solved

little help

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Which Linux flavors will this run on? 6 96
Issues with C++ Class 19 101
Precision Problem in C++ 7 44
How to convert Structure to vector of byte and vice versa 5 24
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…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

828 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