Skip to main content

Posts

Showing posts with the label algorithm implement sort

Sample C Program To Implement Quick Sort Using Pointers, Functions & Arrays.

ALGORITHM: STEP 1: Start the program. STEP 2: Assign the pointer array *a[100] as global, Read the value of n. STEP 3: Set a for loop to read the elements of array. for(i = 0; i < n; i++) STEP 4: Call the function sort(0, n - 1). STEP 5: Print the sorted array a. STEP 6: Stop the program FUNCTION SORT (int first, int last) STEP 1: Declare the local variable. STEP 2: Check if first is less than last. first < last STEP 3: If so then assign the following pivot = a[first] i = first j = last STEP 4: Assign a while loop till the condition. I < j STEP 5: Assign a while loop to increment i till a[i] < pivot and i < last STEP 6: Assign a while loop to decrement j till a[j] > pivot and j > first STEP 7: Check whether i is than j if so then swap the values of a[i] and a[j] temp = a[i] a[j] = a[j] a[j] = temp STEP 8: Then swap the values of a[j] and a[first]. temp = a[j] a[j] = a[first] a[first] =temp STEP 9: Call another f...