C - Swapping nodes in a linked list with a sorting algorithm -


I am working on a project for school where I need to sort a linked list with a sorting algorithm (preferably bubbles) - please -

Note that swapping of each node data is not allowed because I hope to swap nodes. I can not paste all the code in my project because it is very detailed and it is in Spanish, due to which I will show you the parts in which I try to implement the nodes swapping.

, the project is very simple, a linked list where every node has information about a person (name, last name, age, etc.).

I have to sort the alphabetical order according to the list. Please keep in mind that I can not implement the swapping algorithm in sorting and functioning (to say that, I can not create the 'swapnod' function and in the code

I have been successful in swapping two nodes after this argument:

  firstNode = auxiliar-> next; auxiliar-> gt; next = first Node-> next; first node-> gt; next = auxiliar;  

this completely 2 nodes Works for swapping.

The problem is that when I sort all the lists with a sorting algorithm to sort this list, people help me.

I have seen every post about swapping of bubbles coating and node, but I can work on it.

My professor tried to help me, implementing my node swapping code In the following ways (please pay attention to Does that as an example, should be in accordance with the age of the following code):

  while (flag == 1) {auxiliar = firstNode; Flag = 0; If (auxiliar- & gt; Idad & gt; auxiliarSiguiente- & gt; E-father) {firstNode = auxiliar-> Next; Auxiliar- & gt; Next = firstNode-> next; FirstNode-> gt; Next = auxiliar; Flag = 1; } Auxiliar3 = firstNode; While (auxiliar-> Next! = Null) {if (auxiliar-> gt; age> auxiliarNext-> gt; age) {auxiliar2 = auxiliar- & gt; next; Next-> Next = auxiliar2-> next; Auxiliar2- & gt; Next = auxiliar; Auxiliar3- & gt; Next = auxiliar2; } And (auxiliar = auxiliar-> Next;} Auxiliar3 = auxiliar3-> Next;}}  

And then, this code works fine when there are 2 nodes Besides, it does not sort correctly. Besides, I'm not completely sure what my professor uses algorithm.

Maybe what my teacher has done, or maybe doing this

I appreciate you very much

Itemprop = "text"> < P> Your original swap code does not change the next indicator of the node that indicates pointing node auxiliar before swap (which will be If auxiliar is not the first node in the list).


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -