sorting array without subscripts??

i have a simple program to sort a amount of interigers that the user enteres and cannot use subscripts and i just am lost how to do this i just need a simple idea how. i can program and i'm probably over thinking this.
thank you.
josh
Pointers? Iterators? Linked list?
ok that went over my head. i just need the teacher to enter a unknown number of interger and sort them and find the highest and lowest and print the results. I can't use subscripts with is throwing me for a loop (pun intended) i have done this with sub scripts but not without subscrupts.
Use a linked list. There are some good examples on the internet you can get some information form.
Why do you need to store and sort them? You can keep just the lowest and highest numbers, no?

1
2
low = std::min(low, number);
high = std::max(high, number);
i need to output them in order. also.
Well, you can't sort an array without subscripts, although I guess it's possible to sort a linked list without using them.
Are you allowed to use the STL containers or not?
By the way, you mean you can't use arrays right?
Actually... PanGalactic is right, it's irrelevant.
Just slap the code to get a number into a for loop. Keep track of the lowest and highest numbers. If this new number is lower than the current lowest or higher than the current highest (or possibly both if it's your first number) then change the lowest or highest number to the current number. Keep on going around until the teacher inputs a special value to quit the loop.
Not going to give you the code for that though, it's not too complicated to code yourself.
Last edited on
i need to use pointers to put the numbers into an array and sort them into low to high and print out the low high and whole list.
Wait... so you are supposed to use an array but you aren't supposed to use the subscript operator? O_o That will be ugly and inefficient...
OK, well I haven't used pointers in a while, but you probably know how they work with arrays; just increment the pointer's address through the array instead of the subscripting. My question is, how are you supposed to create the array if you don't know how many elements are in it? Does the user input that number at the beginning? (in that case you can do dynamic allocation)
tummy: yes it is ugly and no the user does not enter the number of intergers they enter an eof to quit the input. iam just so lost.
jofl wrote:
i need to output them in order. also.

That's just feature creep.

jofl wrote:
i need to use pointers to put the numbers into an array and sort them into low to high and print out the low high and whole list.


1
2
int array[capacity];
int array_size = 0;


Get input...

1
2
3
4
5
// looping...
cin >> *(array + array_size++);
if (array_size >= capacity) {
    break; // protect your boundaries.
}


Sort input...

1
2
3
std::sort(array, array + array_size);
int low = *array;
int high = *(array + array_size - 1);




ok that is going great Thanks to all and to all a good night merry chirstmas to everyone that help THANKS
josh
Topic archived. No new replies allowed.