Hey,
I have to write a program using vectors that will input a list of positive
integers terminated by a negative integer and output the unique numbers in the list in ascending order? Can anyone help me get started?

Recommended Answers

All 4 Replies

I will definitely need more help than that! What I actualy meant was do I need to convert them to integers and then sort or I can sort them without converting?

Like

int myNumber;
cin >> myNumber;

Well, you can use the string functions to find each number.. example with comma-separated numbers, spaces not allowed:

std::vector<int> v;
std::string numbers; // this is the string with your numbers
std::string::size_type pos = 0;// current position
while(pos != std::string::npos) // as long as current position is valid
{
    std::string::size_type start = pos; // temp storing pos in start
    pos = numbers.find_first_of(',', start); // setting pos to the next pos, which is comma
    v.push_back(atoi(numbers.substr(start, pos-start).c_str())); // cut from start to (next-comma-position minus current-position)
    pos++; // skip next comma, so we should be positioned at the next number
}

Then take a look at
http://www.cplusplus.com/reference/algorithm/sort/

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.