C++ sorting without arrays

I need to sort a series of 25 numbers, entered by the user from smallest to largest, then count the number of times the user entered the number "10". I can't use arrays and I have to use only for loops, can someone please help?
"Without using an array" - Does that mean you're OK to use a linked list or a binary tree? (or a Standard Library container?)


Or do you mean that you're trying to sort a series of numbers at the time they're input without storing them in any kind of container/list/tree/etc? If its the latter, then the only reasonable way to do it would be recursion.
It means that I can't use an array formatted as "Array[25]" and I can only use for loops.
In this case you could simply use a list and use iterators to determine where you need to insert your element? Then, once the list is formed you just iterate over it and count tens.
Edit: Check out this reference: http://www.cplusplus.com/reference/stl/list/
Last edited on
I figured it out, I misread the question.

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
#include <iostream>
using namespace std;
 
int main()
{
	int max;
	int min;
	int ten=0;
	int total;
	int i;
	cout << "Please Enter a number" << endl;
	cin >> max;
 
	min=max;
	total=max;
 
	if (max==10)
		ten++;
	for (int x=1; x<25; x++)
	{
		cout << "Please Enter a number" << endl;
		cin >> i;
 
		if (i>max)
			max=i;
		if (i<min)
			min=i;
		if (i==10)
			ten++;
		total += i;
	}
	cout << "Max =  " << max << endl << "Min =  " << min << endl << "There were  " << ten << " 'tens' entered" << endl; 
 
}
Topic archived. No new replies allowed.