| | |
critical count for quicksort??
![]() |
•
•
Join Date: Mar 2005
Posts: 73
Reputation:
Solved Threads: 0
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
i used a naive sort and was able to show a critical count for that as shown below:
critical count for naive sort
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!!
Basically my cd database is almost finished.
What i need to do is show a critical count for the quicksort
quicksort for my database
C Syntax (Toggle Plain Text)
void q_sort (struct CdRecords array [], int count) { quick_sort(array,0,count-1); } void quick_sort (struct CdRecords array [], int left, int right) { int i, j; char *x; struct CdRecords temp; i = left; j = right; x = array[(left+right)/2].Genre; do { while(strcmp(array[i].Genre,x)<0 && i<right) i++; while(strcmp(array[i].Genre,x)>0 && j>left) j--; if(i<=j) { temp = array[i]; array[i] = array[j]; array[j] = temp; i++; j--; } }while(i<=j); if(left<j) quick_sort(array, left, j); if(i<right)quick_sort(array, i, right); }
i used a naive sort and was able to show a critical count for that as shown below:
C Syntax (Toggle Plain Text)
void naive_sort (struct CdRecords array [], int arraySize, int * count) { for (int pass = 0; pass <= arraySize - 2; pass++) { for (int counter = 0; counter <= arraySize - 2-pass; counter++) { *count = *count + 1; // count critical operations if (strcmp(array[counter].Artist,array[counter+1].Artist)>0) swap (&array[counter], &array[counter+1]); } } } // Exchange a given pair of values in an array void swap (struct CdRecords * v1, struct CdRecords * v2) { struct CdRecords temp; temp = *v1; *v1 = *v2; *v2 = temp; }
critical count for naive sort
C Syntax (Toggle Plain Text)
void sort_critical_count(struct CdRecords cdDB[],int choice) { int count = 0; naive_sort (cdDB, datasize, & count); if(choice == 5) printf("\nCritical count is : %d\n",count); else printf("Array has been sorted"); printf("Press Enter To Continue"); fflush(stdin); getch(); }
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!!
>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.
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.
•
•
Join Date: Mar 2005
Posts: 73
Reputation:
Solved Threads: 0
[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..
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..
>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:
Format the file as necessary to get the spreadsheet that you want.
It's pretty straightforward. Open a file and write the values to it, separated by commas:
C Syntax (Toggle Plain Text)
FILE *out = fopen ( "somefile", "w" ); while ( !done ) { /* Do something with counter */ fprintf ( out, "%d", counter ); if ( !done ) fputc ( ',', out ); } fclose ( out );
I'm here to prove you wrong.
•
•
Join Date: Mar 2005
Posts: 73
Reputation:
Solved Threads: 0
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!!
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!!
![]() |
Similar Threads
- Finally Almost Finished 2 Problems!! :( (C)
- where am i going wrong!!sort & crit count (C)
- Please help with my quicksort (C)
- Quicksort/Insertion sort Hyrbid? (C)
Other Threads in the C Forum
- Previous Thread: file handling code
- Next Thread: Some help
| Thread Tools | Search this Thread |
#include * adobe ansi array asterisks binarysearch centimeter changingto char character cm convert copyimagefile cprogramme creafecopyofanytypeoffileinc database dynamic execv feet fgets file floatingpointvalidation fork function getlogicaldrivestrin givemetehcodez global grade gtkwinlinux hacking histogram ide inches include incrementoperators infiniteloop input interest intmain() iso kernel keyboard kilometer license linked linkedlist linux list locate looping lowest match matrix meter microsoft number oddnumber opendocumentformat opensource openwebfoundation owf pattern pdf performance pointer posix power probleminc process program programming radix recursion recv recvblocked research reversing segmentationfault sequential single socket socketprograming socketprogramming standard strchr string suggestions systemcall test threads turboc unix urboc user variable voidmain() wab whythiscodecausesegmentationfault windowsapi






