![]() |
| ||
| help by sorting a simply linked list 1 Attachment(s) Hi! Pls, somebody help me!! I'm stuck here since days. I don't know, what i'm doing wrong. |
| ||
| Re: help by sorting a simply linked list Hello, I looked at your code, and it appears to be a bubble-sort. Here is what I would do. 1) Get yourself a nice sheet of paper, and a pencil. 2) Draw out your data structure. [CODE] +-------+ +------------------+ +------------------+ | head | | data | point | | data | point | +-------+ +------------------+ +------------------+ [\CODE] Remember to draw little boxes for the temp pointers and stuff too. 3) Go through your code by hand, and fill in the paper as the computer would during the iterations. Do not assume when doing this by hand. Go through the motions, and stick with it. You will find your error. 4) In my coding days, I was always sure to make a duplicate head pointer, just in case I messed up the transition somewhere. Guess it was mild parinoia. Christian |
| ||
| Re: help by sorting a simply linked list Hello my brother there is two way to sort a single linked list First , swapping data but it is unsufficient (( suppose the data is very bug)) Second, swapping pointer is better but it's harder here you are the two ways Swapping the pointers void Sortable_List::sort() Swapping Data NodeEmp *Ptr1,*Ptr2; |
| ||
| Re: help by sorting a simply linked list Quote:
I finally found the solution. I'm posting the method for sorting below: void List::listsort(){P..S. i live in germany and this programm is for the university of münchen. Therefore, the comments are in german. And also, i come from ecuador, so my mother language is spanish. So, anterior means previous. |
| All times are GMT -4. The time now is 8:22 pm. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC