Trying to bubble sort
+- PA02_Main +- PA02_Main.c +- StateUtilities.c
This commit is contained in:
parent
a88b49135b
commit
f48c96705e
3 changed files with 27 additions and 6 deletions
Binary file not shown.
|
|
@ -72,7 +72,7 @@ int main()
|
|||
// display original list
|
||||
displayData( wkgArray, wkgNumStates,
|
||||
"Original data after state removal" );
|
||||
/*
|
||||
|
||||
// bubble sort
|
||||
// function: runBubbleSort
|
||||
runBubbleSortByName( sortingArray, sortingNumStates );
|
||||
|
|
@ -80,7 +80,7 @@ int main()
|
|||
// display bubble-sorted list
|
||||
displayData( sortingArray, sortingNumStates,
|
||||
"Full list sorted by name using bubble sort" );
|
||||
|
||||
/*
|
||||
// insertion sort
|
||||
// function: runInsertionSort
|
||||
runInsertionSortByPopulation( sortingArray, sortingNumStates );
|
||||
|
|
|
|||
|
|
@ -395,10 +395,31 @@ Dependencies: as needed
|
|||
*/
|
||||
void runBubbleSortByName( StateDataType *array, int size )
|
||||
{
|
||||
// start iterator at size - 2?
|
||||
// iterate through iterator
|
||||
// check the current index vs the next one.
|
||||
// if current > next, swap.
|
||||
int bubbleCount;
|
||||
int arrayCount;
|
||||
printf("\nArray @ 0: %s\n", array[0].name);
|
||||
printf("\nArray @ 1: %s\n", array[1].name);
|
||||
printf("\nArray @ 2: %s\n", array[2].name);
|
||||
printf("\nArray @ 3: %s\n", array[3].name);
|
||||
printf("\nArray @ 4: %s\n", array[4].name);
|
||||
printf("\nArray @ size: %s\n", array[size].name);
|
||||
// use two for loops to iterate through array
|
||||
// for(bubbleCount = 0; bubbleCount < size - 1; bubbleCount++)
|
||||
// {
|
||||
// for(arrayCount = bubbleCount + 1; arrayCount < size; arrayCount++)
|
||||
// {
|
||||
// printf("\nValue of bubbleCount: %d\n", bubbleCount);
|
||||
// printf("\nValue of arrayCount: %d\n", arrayCount);
|
||||
// //printf("\nValue of array[arrayCount].name: %s", array[0].name);
|
||||
// //printf("\nValue of array[arrayCount + 1].name: %s\n", array[1].name);
|
||||
// // check the current index vs the next one.
|
||||
// if(strcmp(array[arrayCount].name, array[arrayCount + 1].name) > 0)
|
||||
// {
|
||||
// // if current > next, swap. AKA: strcmp(current, next) > 0
|
||||
// swapElements(array, arrayCount, arrayCount + 1);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// no return, void
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue