• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 221
  • Last Modified:

SortbyNumber NODEs

In a linked list representation of a data stucture that represents a student and their grade; how can a sort be implemented to link the list in descending order according to their score? struct STUD { char *name; int score; STUD* next}; class ROSTER{ STUD *claslist; void sortbyNumber();};
1 Solution
Sorting a linked list is incredibly slow.  You would do better
do collect an array of pointers and then use qsort() - then do
whatever sorted processing you want on your array of pointers.


void ROSTER::sortbyNumber()
   STUD *tmp;
   STUD *min;

I didn't compile it; but the idea is simple.
If you ever arranged arrays of main types - it will be obviously for you. In loop untill last element is reached(min->next!=NULL) compare score of current node and first in list. If necessary-change them to each other.
Hope that will help you.
184197Author Commented:
I was getting stuck on the for loop.  Thank you for helping me.  
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now