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
|
// display original list
|
||||||
displayData( wkgArray, wkgNumStates,
|
displayData( wkgArray, wkgNumStates,
|
||||||
"Original data after state removal" );
|
"Original data after state removal" );
|
||||||
/*
|
|
||||||
// bubble sort
|
// bubble sort
|
||||||
// function: runBubbleSort
|
// function: runBubbleSort
|
||||||
runBubbleSortByName( sortingArray, sortingNumStates );
|
runBubbleSortByName( sortingArray, sortingNumStates );
|
||||||
|
|
@ -80,7 +80,7 @@ int main()
|
||||||
// display bubble-sorted list
|
// display bubble-sorted list
|
||||||
displayData( sortingArray, sortingNumStates,
|
displayData( sortingArray, sortingNumStates,
|
||||||
"Full list sorted by name using bubble sort" );
|
"Full list sorted by name using bubble sort" );
|
||||||
|
/*
|
||||||
// insertion sort
|
// insertion sort
|
||||||
// function: runInsertionSort
|
// function: runInsertionSort
|
||||||
runInsertionSortByPopulation( sortingArray, sortingNumStates );
|
runInsertionSortByPopulation( sortingArray, sortingNumStates );
|
||||||
|
|
|
||||||
|
|
@ -395,10 +395,31 @@ Dependencies: as needed
|
||||||
*/
|
*/
|
||||||
void runBubbleSortByName( StateDataType *array, int size )
|
void runBubbleSortByName( StateDataType *array, int size )
|
||||||
{
|
{
|
||||||
// start iterator at size - 2?
|
int bubbleCount;
|
||||||
// iterate through iterator
|
int arrayCount;
|
||||||
// check the current index vs the next one.
|
printf("\nArray @ 0: %s\n", array[0].name);
|
||||||
// if current > next, swap.
|
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
|
// no return, void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue