Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Keep your lined list objects in the lined list, in random order. To sort the list by any key, use this pseudocode:</p> <pre><code>struct LinkedList { string name; LinkedList *prev; LinkedList *next; }; void FillArray(LinkedList *first, LinkedList **output, size_t &amp;size) { //function creates an array of pointers to every LinkedList object LinedList *now; size_t i; //you may use int instead of size_t //check, how many objects are there in linked list now=first; while(now!=NULL) { size++; now=now-&gt;next; } //if linked list is empty if (size==0) { *output=NULL; return; } //create the array; *output = new LinkedList[size]; //fill the array i=0; now=first; while(now!=NULL) { *output[i++]=now; now=now-&gt;next; } } SortByName(LinkedList *arrayOfPointers, size_t size) { // your function to sort by name here } void TemporatorySort(LinkedList *first, LinkedList **output, size_t &amp;size) { // this function will create the array of pointer to your linked list, // sort this array, and return the sorted array. However, the linked // list will stay as it is. It's good for example when your lined list // is sorted by ID, but you need to print it sorted by names only once. FillArray(first, *output, size); SortByName(output,size); } void PermanentSort(LinkedList *first) { // This function will sort the linked list and save the new order // permanently. LinkedList *sorted; size_t size; TemporatorySort(first,&amp;sorted,size); if (size&gt;0) { sorted[0].prev=NULL; } for(int i=1;i&lt;size;i++) { sorted[i-1].next=sorted[i]; sorted[i].prev=sorted[i-1]; } sorted[size-1].next=NULL; } </code></pre> <p>I hope, I actually did help you. If you don't understand any line from the code, simply put a comment to this "answer".</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload