Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Apr 3rd, 2007, 11:23 PM   #1
cwl157
Professional Programmer
 
Join Date: Feb 2005
Posts: 343
Rep Power: 4 cwl157 is on a distinguished road
sorting an array by field

Hi I need to know how to sort an array of stucts based on one of the fields. I have to go from smallest to largest. The struct has 4 fields in it: int processNbr; int totalTime; int remainingTime; int stopTime; int isFinished;. I think i'm really only concerned with processNbr and totalTime I have it to where it finds and prints the smallest ok but from there i dont know how to "scratch that one off the list" and find the next one and print it and then find the next largest and print it. I have a for loop go through the array to find the smallest but then how do i run through it again to find the next smallest. I'll post the function that i'm talking about. It is for a cpu time schedule simulator for shortest job first job processing method thats why i need to sort by the totalTime field and put the smallest first, followed by the next smallest and so on and then somehow keep track of the order so i can print the processNbr and totalTime for each of them in the order they would finish at the end.
 //###################################################################
void scheduleSJF(processDataType processes[], int processCount)
{
  int i;
  int minimumProcessTimeIndex;
  int minimumProcessRunningTime = processes[0].totalTime;
  for (i = 1; i < processCount; i++)
  {
    if (processes[i].totalTime < minimumProcessRunningTime)
    {
       minimumProcessRunningTime = processes[i].totalTime;
       minimumProcessTimeIndex = i;
    } // end if
  } // end for
  printf("the lowestRunning time is %d\n", minimumProcessRunningTime);
  printf("the minimumProcessTimeIndex is %d\n", minimumProcessTimeIndex);

} // end sechudleSJF
cwl157 is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
changing size of an array Eric the Red Java 3 Apr 3rd, 2006 8:19 PM
Sorting an array of objects oNe8 Java 2 Feb 22nd, 2006 10:59 PM
Sorting without a large array sim_maroon C 12 Nov 21st, 2005 8:45 PM
Sorting a Numeric Array little_valaree Java 2 Nov 21st, 2005 11:00 AM
Installing IPB 2.03 bh4575 Other Web Development Languages 0 Apr 23rd, 2005 2:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:24 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC