0

I am trying to order a list of records by their lastname field which is type char array, i'm using the strcmp() function in my algorithm and I cannot sort out where it's going wrong.. the function's add to front and add to back feature work ok, it's just the add to middle, i get output like

Enter order 0 - Ascending, 1 - Descending: 0 2 5 3 4 6

If anybody here can see the problem give me a shout!

Main.cpp (basically just the menu)

Ktmock13
  • 145
  • 1
  • 2
  • 15

1 Answers1

3

You forgot to update s2 and s3 in the while loop that seeks through the list (s1 doesn't change as far as I can see).

Moving

while(current!=last && x!=1)
{

up by two or three lines might do the trick.

You should also check whether the if-block after the loop is necessary.

gnome
  • 301
  • 2
  • 10
  • [here](http://stackoverflow.com/questions/15179996/how-should-i-allocate-memory-for-c-string-char-array?answertab=votes#tab-top) you suggestion was helpful :) – Grijesh Chauhan Mar 02 '13 at 22:34