Created
          May 20, 2018 22:20 
        
      - 
      
 - 
        
Save axsddlr/08dd455c200a5f461ede5d214aefc400 to your computer and use it in GitHub Desktop.  
    SlimImpossibleArchitecture created by Ayysir - https://repl.it/@Ayysir/SlimImpossibleArchitecture
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | #include <stdio.h> | |
| #include <stdbool.h> | |
| #define MAX 9 | |
| int intArray[MAX] = {1, 3, 9, 4, 11, 34, 2, 8, 10}; | |
| void printline(int count) { | |
| int i; | |
| for(i = 0;i < count-1;i++) { | |
| printf("="); | |
| } | |
| printf("=\n"); | |
| } | |
| void display() { | |
| int i; | |
| printf("["); | |
| // navigate through all items | |
| for(i = 0;i < MAX;i++) { | |
| printf("%d ",intArray[i]); | |
| } | |
| printf("]\n"); | |
| } | |
| void swap(int num1, int num2) { | |
| int temp = intArray[num1]; | |
| intArray[num1] = intArray[num2]; | |
| intArray[num2] = temp; | |
| } | |
| int partition(int left, int right, int pivot) { | |
| int leftPointer = left -1; | |
| int rightPointer = right; | |
| while(true) { | |
| while(intArray[++leftPointer] < pivot) { | |
| //do nothing | |
| } | |
| while(rightPointer > 0 && intArray[--rightPointer] > pivot) { | |
| //do nothing | |
| } | |
| if(leftPointer >= rightPointer) { | |
| break; | |
| } else { | |
| printf(" item swapped :%d,%d\n", intArray[leftPointer],intArray[rightPointer]); | |
| swap(leftPointer,rightPointer); | |
| } | |
| } | |
| printf(" pivot swapped :%d,%d\n", intArray[leftPointer],intArray[right]); | |
| swap(leftPointer,right); | |
| printf("Updated Array: "); | |
| display(); | |
| return leftPointer; | |
| } | |
| void quickSort(int left, int right) { | |
| if(right-left <= 0) { | |
| return; | |
| } else { | |
| int pivot = intArray[right]; | |
| int partitionPoint = partition(left, right, pivot); | |
| quickSort(left,partitionPoint-1); | |
| quickSort(partitionPoint+1,right); | |
| } | |
| } | |
| int main() { | |
| printf("Input Array: "); | |
| display(); | |
| printline(50); | |
| quickSort(0,MAX-1); | |
| printf("Output Array: "); | |
| display(); | |
| printline(50); | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment