Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


SortbyNumber NODEs

Posted on 1999-01-25
Medium Priority
Last Modified: 2010-04-02
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();};
Question by:184197
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 1185132
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.


Accepted Solution

MCoroli earned 300 total points
ID: 1185133

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.

Author Comment

ID: 1185134
I was getting stuck on the for loop.  Thank you for helping me.  

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question