Problems with display

I figured out the reason behind the scenes of my last post; however, I have a problem that I want to get solved. My code that is useful to this post is below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
class numbers
{
public:
	void add(int n);          // Adds a new number to the end of the vector
	int remove(int i);        // Removes the element at the specified index of the vector
	void sort_up();           // Calls the private function sort_up function
    void sort_down();         // Calls the private recursive sort_down function
	void display();           // Prints the vector to the screen
private:
	vector <int> numbers;
	vector <int> sort_down(vector <int> unsorted_list);
	vector <int> sort_up(vector <int> unsorted_list);
};
int numbers::remove(int index)
{
    if ((index >= 0) && (index + 1 <= numbers.size()))
    {
        numbers.erase(numbers.begin() + index);
        for (int i = 0; i < numbers.size(); i++)
            cout << numbers[i] << " ";
        cout << endl;
    }
    else
    {
        cout << "Invalid index, element either below zero or has exceeded the size of the array";
        cin.get();
    }
}

void numbers::sort_down()
{
    numbers = sort_down(numbers);
}
vector <int> numbers::sort_down(vector <int> unsorted_list)
{
      int max, count = 0;
      if (unsorted_list.size() == 1)
      {
         cout << unsorted_list[0];
      }
      else
      {
          max = unsorted_list[0];
          for (int i = 0; i < unsorted_list.size(); i++)
          {
              if (max < unsorted_list[i])
              {
                 max = unsorted_list[i];
                 count = i;
              }
          }
          cout << max << " ";
          numbers::remove(count);
          numbers::sort_down(); 
      }
}


My first problem is that my sort function isn't really in the way that I envisioned. My purpose of the sort_down function is to find the maximum value in the array, remove that element and then continue until the size of the array is one. My problem is that I am removing/outputting the max. element but I cannot seem to get around displaying the entire array every iteration. A simple example of what I my screen looks like:

vector: 1 4 2 6 3 5
display:
6 -- 1 4 2 3 5
5 -- 1 4 2 3
4 -- 1 2 3
3 -- 1 2
2 -- 1
1 --

when the output should be:
display: 6 5 4 3 2 1


What can I do to avoid this?! Thank you for all of the help!
Topic archived. No new replies allowed.