![]() |
| ||
| Link List Sorting Problem i tried for sorting the link list for weeks already, and yet still couldnt get the output as what i want. i search through the forum and i found the coding "algorithm" (in blue color) for sorting...but it seems tooo alit bit toooooooooooo long. so far, i was trying to implement the same way as bubble sorting, but still...can not get answer :sad: . i tried using the elements, just like in bubble sort, for example:
still can not also.. i hope that some experts out there could help me in this problem....giving me advice(s). i really headache already...couldn't figure out anything.... thanks below here is my coding: #include <iostream><< moderator edit: added [code][/code] tags >> |
| ||
| Re: Link List Sorting Problem Don't try to bubble sort a linked list, it's bad enough for arrays. There are two sorting algorithms that lend themselves well to sorting linked lists: insertion sort and merge sort. However, selection sort is also easy to visualize and to implement. |
| ||
| Re: Link List Sorting Problem well, actually i want to try to sort it out by using bubble sort...curious to know how it works...i tried many times already, yet no result...i hope that you could help me :-| thanks |
| ||
| Re: Link List Sorting Problem >curious to know how it works Just like bubble sort with an array except crappier. >i hope that you could help me The best way to bubble sort a linked list is to cheat by swapping the data instead of splicing the nodes: void abc::sorting()Splicing nodes makes it ten times harder and less efficient, which is a feat for bubble sort since it sucks so much to begin with. Off the top of my head, it might look something like this: void abc::sorting() |
| ||
| Re: Link List Sorting Problem thanks but i found the way, yesterday..finally :cool: , but from what u said, it is bad to use bubble sorting in linked list.. i tried to implement merge sorting, and insertion...but i find it..the codings were soooooo faaacinating...haha..(u know ..lazy for long typing..haha) this is my coding using "bubble sort", mind to give any comment(s) about my coding...thanks for the help. i'm glad to learn from you. void abc::sorting() { Node *cur = head; cur = cur->next; int hold; int i = 0; for( ; i < SIZE ; i++) { for(Node *pvr = head; cur != NULL; cur=cur->next , pvr = pvr ->next) { if(pvr->num > cur->num) { hold = pvr->num; pvr->num = cur->num; cur->num = hold; } } cur = head; cur=cur->next; pvr=head; } } |
| All times are GMT -4. The time now is 11:17 am. |
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC