I have an assignment to create an ordered list using templates so that it will accept all data types. I believe I have the template part of the program correct, but for some reason I can't get my list to come out in order. Here's my code so far:
I think that your OrderedList isn't functioning at all.
The output going to the file comes from lines 150 and 171 where you are writing the values directly after generating them.
You haven't allocated memory space for the data array anywhere. You would be getting lots of segmentation faults, but luckily currSize remains always = 0 so your add() and some of the for loops in main() do nothing (because orderedlist.size() returns 0).
Start fixing this by allocating an array to data in the OrderedList constructor.
Rewrite the add(). There are several logical errors present.
You are exceeding the array bounds in the add() for 2 reasons.
1) Increasing the value of maxSize doesn't increase the # of elements allocated to data:
1 2
if(currSize >= maxSize)
maxSize +=5;
You need to allocate a new larger array to a temp*, copy the values from the existing array to the new one, delete the old array then assign data to point to the new array.
2)More subtle here... currSize = the # of elements in use = 1 more than the max valid array index.
In the for loop on lines 101, 102
you are referencing data[currSize+1] in the 1st iteration. Keep in mind that if maxSize = 10 then currSize can be as high as 9. Try for(int j = currSize-1; j >= k; j--).
I see a similar issue in your remove().
You need to allocate an array in the copy constructor like you did in the default constructor.
This is all I can see that's wrong with the code. Good luck!
Alright I finally got it working. Thank you very much for all of your help and pointing out where I could fix it without just telling me what to type. Hopefully I learned something this way ha ha.