Advertisement
Guest User

dsfsdf10

a guest
Dec 11th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. //Omar Savion Youssef
  2. //HW #10
  3. #include <iostream>
  4. #include <algorithm>
  5. #include <fstream>
  6.  
  7. using namespace std;
  8.  
  9. ofstream outfile("myOutput.txt");
  10.  
  11. int partyOfNumbers[10];
  12.  
  13. void quickSort(int [], int, int);
  14.  
  15. int partition(int [], int, int);
  16.  
  17. int main(){
  18. cout<<"Please Enter 10 numbers to be sorted... Please Please.";
  19.     for(int i=0;i<10;i++){
  20.         cin>>partyOfNumbers[i];
  21.     }
  22.  
  23.     /* Use for DEBUGGING
  24.     for (int j=0; j < 10; j++){
  25.     cout<<partyOfNumbers[j]<<endl;
  26.     }
  27.     */
  28.  
  29.     quickSort(partyOfNumbers,0,9);
  30.  
  31.     for (int j=0; j < 10; j++){
  32.         cout<<partyOfNumbers[j]<<endl;
  33.     }
  34.  
  35.     for (int j=0; j < 10; j++){
  36.     outfile<<partyOfNumbers[j]<<endl;
  37.     }
  38.  
  39.     return 0;
  40. }
  41.  
  42. void quickSort(int arr[],int left,int right){
  43.         if(left < right){
  44.         int ptr= partition(arr,left,right);
  45.         quickSort(arr,left,ptr-1);
  46.         quickSort(arr,ptr+1,right);
  47.         }
  48.     }
  49.  
  50. int partition(int arr[],int left,int right){
  51.     int pivotValue=arr[left];
  52.     int pivotPosition = left;
  53.  
  54.  
  55.     for(int pos=left+1 ; pos <= right; pos++)
  56.     {
  57.         if(arr[pos] < pivotValue){
  58.         swap(arr[pivotPosition + 1],arr[pos]);
  59.         swap(arr[pivotPosition],arr[pivotPosition+1]);
  60.         pivotPosition++;
  61.             }
  62.     }
  63.     return pivotPosition;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement