Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Omar Savion Youssef
- //HW #10
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- using namespace std;
- ofstream outfile("myOutput.txt");
- int partyOfNumbers[10];
- void quickSort(int [], int, int);
- int partition(int [], int, int);
- int main(){
- cout<<"Please Enter 10 numbers to be sorted... Please Please.";
- for(int i=0;i<10;i++){
- cin>>partyOfNumbers[i];
- }
- /* Use for DEBUGGING
- for (int j=0; j < 10; j++){
- cout<<partyOfNumbers[j]<<endl;
- }
- */
- quickSort(partyOfNumbers,0,9);
- for (int j=0; j < 10; j++){
- cout<<partyOfNumbers[j]<<endl;
- }
- for (int j=0; j < 10; j++){
- outfile<<partyOfNumbers[j]<<endl;
- }
- return 0;
- }
- void quickSort(int arr[],int left,int right){
- if(left < right){
- int ptr= partition(arr,left,right);
- quickSort(arr,left,ptr-1);
- quickSort(arr,ptr+1,right);
- }
- }
- int partition(int arr[],int left,int right){
- int pivotValue=arr[left];
- int pivotPosition = left;
- for(int pos=left+1 ; pos <= right; pos++)
- {
- if(arr[pos] < pivotValue){
- swap(arr[pivotPosition + 1],arr[pos]);
- swap(arr[pivotPosition],arr[pivotPosition+1]);
- pivotPosition++;
- }
- }
- return pivotPosition;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement