![]() |
How to sort doubly-linked list? BFP
My first post! Congratulations :)
BFP = Big F**king Problem :) First...I'm sorry if my English is wrong!(I'm from Bulgaria) Second: Please don't delete my Post! I've read at least 20 sites with google search and in a lot of forums to understand and repair my problem! So just please help. Third: Before one week, I know only few about Programming in C, some arrays, basic things, the loops, but my source is over 1200 lines, so help me to finish it, please. I'm trying to sort a doubly-linked list without any success for 3 days! Please help me, I know, that you can. So... The idea is to sort the first two elements, than to compare the next two and something like that...Yet I'm very very CONFUSED. this is my struct for an element of the doubly-linked list: Code: C
For Example: I must sort that dates: 11.11.2003 11.12.2003 11.11.2006 11.11.2004 11.11.2005 11.11.2007 like that: 11.11.2007>11.11.2006>11.11.2005>11.11.2004>11.12> 2003>11.11.2003 Important: We don't know the number of the workers, and when we sort the list, we can add more workers, and than we must sort with the new again for example. in that code, I add workers to the list: Code: C
and the dates of elements (workers) are like the example before...in that row. FOR SORT: I tried lot of ways, but nothing work!!! like that for example: Code: C
or: Code: C
or other ways, that I haven't yet, but they don't work. THANKS A LOT! |
Re: How to sort doubly-linked list? BFP
Sorry, that pale colored text is too hard to read. Further, you haven't put the code inside tags to preserve it's indentation. Let me recommend you read the "BEFORE you make a query" thread. You'll find a link in the upper right corner of this page.
Don't know why you would want to make it difficult for potential helpers, but there you have it. |
Re: How to sort doubly-linked list? BFP
Sorry, but for now, you can just select the text with the mouse. I thought that this colors are the formated C-code...like in other posts :| Sorry again!
|
Re: How to sort doubly-linked list? BFP
Quote:
|
Re: How to sort doubly-linked list? BFP
Quote:
P.S. Now I test to have two temp elements for each element that will be swapped, but something don't work. Can anyone help, just to say, can I do that, that I want, is it possible as a logical idea? Thanks |
Re: How to sort doubly-linked list? BFP
swap (a, b) => move a to temp, move b to a, move temp to b.
|
Re: How to sort doubly-linked list? BFP
I have not gone through the complete thread but just from the title it seems Sort Linked List article would interest you.
|
Re: How to sort doubly-linked list? BFP
Let me point out that there are at least 3 ways to sort a linked list. Suppose that your inspection of the variables used in the sort criteria indicate that you should swap elements 2 and 7.
You can exchange all the data for elements 2 and 7, except for the links. You can exchange the links for elements 2 and 7. You can establish an array of pointers to the elements and merely swap the pointers in the array. |
| All times are GMT +5.5. The time now is 04:21. |