critical count for quicksort??

Reply

Join Date: Mar 2005
Posts: 73
Reputation: nabil1983 is an unknown quantity at this point 
Solved Threads: 0
nabil1983 nabil1983 is offline Offline
Junior Poster in Training

critical count for quicksort??

 
0
  #1
Dec 7th, 2005
Does anyone know the code to show the critical count for a quick sort algorithm.
Basically my cd database is almost finished.
What i need to do is show a critical count for the quicksort


quicksort for my database
  1. void q_sort (struct CdRecords array [], int count)
  2. {
  3. quick_sort(array,0,count-1);
  4. }
  5. void quick_sort (struct CdRecords array [], int left, int right)
  6. {
  7. int i, j;
  8. char *x;
  9. struct CdRecords temp;
  10.  
  11. i = left;
  12. j = right;
  13.  
  14. x = array[(left+right)/2].Genre;
  15.  
  16. do {
  17. while(strcmp(array[i].Genre,x)<0 && i<right) i++;
  18. while(strcmp(array[i].Genre,x)>0 && j>left) j--;
  19. if(i<=j) {
  20. temp = array[i];
  21. array[i] = array[j];
  22. array[j] = temp;
  23. i++; j--;
  24.  
  25. }
  26.  
  27. }while(i<=j);
  28.  
  29. if(left<j) quick_sort(array, left, j);
  30. if(i<right)quick_sort(array, i, right);
  31. }



i used a naive sort and was able to show a critical count for that as shown below:

  1. void naive_sort (struct CdRecords array [], int arraySize, int * count)
  2. {
  3. for (int pass = 0; pass <= arraySize - 2; pass++)
  4. { for (int counter = 0; counter <= arraySize - 2-pass; counter++)
  5. {
  6. *count = *count + 1; // count critical operations
  7. if (strcmp(array[counter].Artist,array[counter+1].Artist)>0)
  8. swap (&array[counter], &array[counter+1]);
  9. }
  10. }
  11. }
  12.  
  13. // Exchange a given pair of values in an array
  14. void swap (struct CdRecords * v1, struct CdRecords * v2)
  15. {
  16. struct CdRecords temp;
  17. temp = *v1;
  18. *v1 = *v2;
  19. *v2 = temp;
  20. }

critical count for naive sort

  1. void sort_critical_count(struct CdRecords cdDB[],int choice)
  2. {
  3. int count = 0;
  4. naive_sort (cdDB, datasize, & count);
  5. if(choice == 5)
  6. printf("\nCritical count is : %d\n",count);
  7. else
  8. printf("Array has been sorted");
  9. printf("Press Enter To Continue");
  10. fflush(stdin);
  11. getch();
  12. }


neone know how i can implement this for the quicksort coding shown above !!
Also does neone know how u can output data ontoa excel spreadsheet??

apreciate all help!!
u all been a great help in recent days!!
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: critical count for quicksort??

 
0
  #2
Dec 8th, 2005
>Does anyone know the code to show the critical count for a quick sort algorithm.
Use a global variable, and realize that all of the work is done in the partitioning step of the algorithm. Beyond that, it's pretty simple to add a critical counter to quicksort.

>Also does neone know how u can output data ontoa excel spreadsheet?
Well, you could meander over to www.wotsit.org and try to actually output an xls file...or you could take the easier route and output a comma delimited file, then import it into Excel.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 73
Reputation: nabil1983 is an unknown quantity at this point 
Solved Threads: 0
nabil1983 nabil1983 is offline Offline
Junior Poster in Training

Re: critical count for quicksort??

 
0
  #3
Dec 8th, 2005
[QUOTE=NarueUse a global variable, and realize that all of the work is done in the partitioning step of the algorithm.

or you could take the easier route and output a comma delimited file, then import it into Excel.[/QUOTE]

is there any example i can see for comma delimited file and could you explain the use of the Global Variable and Partitioning Step...
IM in a learning stage of C, but need info on these asap..
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 73
Reputation: nabil1983 is an unknown quantity at this point 
Solved Threads: 0
nabil1983 nabil1983 is offline Offline
Junior Poster in Training

Re: critical count for quicksort??

 
0
  #4
Dec 8th, 2005
sorry mate ignore the partition and global variable quetion in my last post..
i just need to know aboutt comma delimmited files, how do i do it im quite confused on this one....
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 7,625
Reputation: Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute Narue has a reputation beyond repute 
Solved Threads: 714
Team Colleague
Narue's Avatar
Narue Narue is offline Offline
Code Goddess

Re: critical count for quicksort??

 
0
  #5
Dec 8th, 2005
>i just need to know aboutt comma delimmited files, how do i do it im quite confused on this one....
It's pretty straightforward. Open a file and write the values to it, separated by commas:
  1. FILE *out = fopen ( "somefile", "w" );
  2.  
  3. while ( !done ) {
  4. /* Do something with counter */
  5.  
  6. fprintf ( out, "%d", counter );
  7.  
  8. if ( !done )
  9. fputc ( ',', out );
  10. }
  11.  
  12. fclose ( out );
Format the file as necessary to get the spreadsheet that you want.
I'm here to prove you wrong.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 73
Reputation: nabil1983 is an unknown quantity at this point 
Solved Threads: 0
nabil1983 nabil1983 is offline Offline
Junior Poster in Training

Re: critical count for quicksort??

 
0
  #6
Dec 8th, 2005
I've tried that but for some reason it dont work. The program im working on is in the last Post i put. 'Finally Almost Finished 2 Problems!!'
Take a look there , cuz i got two vital problems in there. I've spent days and hours on this project and just these few things are giving me the problem.

I apreciate the help u've already given!!
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC