hi all,
before i get any post about how pointless a recursive insertion is...i know it is...but it's for an assignment...and i've been playing around w/ it 'till the point where i can't tell what's wrong w/ it anymore...
it's doing a semi sort...i think i'm forgetting to take into acct a case ..but either way...here's the code.
being passed an object of the class list (w/h is a Linked List) and n which is the size of the list.
most of this stuff is self explanatory...
insert, inserts in list @ location specified.
remove...removes @ location specified.
here's my data,
20 19 14 23 16 10 18
and this is my output:
10 14 16 18 20 19 23
any help would be appreciated.
oh yeah.. getvalue returns the value @ location specified.
(class deals w/ either ints, float, or string but data type shouldn't matters it's a template after all)
template<class T>
void insort1(List<T>& list, int n)
{
if (n > 1)
{
insort1(list, n -1);
int posn = n -1;
while (posn >= 0 && (list.getvalue(n) < list.getvalue(posn)) )
posn--;
posn++;
T temp;
temp = list.getvalue(n);
list.remove(n,temp);
list.insert(posn,temp);
}
}



LinkBack URL
About LinkBacks


