Skip to content

Commit

Permalink
quick sort
Browse files Browse the repository at this point in the history
  • Loading branch information
NasreenParween committed Jul 4, 2022
1 parent 1932ea5 commit 967990e
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 0 deletions.
40 changes: 40 additions & 0 deletions DAA_QUICK_SORT/DAA_QUICK_SORT.cbp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_project_file>
<FileVersion major="1" minor="6" />
<Project>
<Option title="DAA_QUICK_SORT" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/DAA_QUICK_SORT" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Debug/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-g" />
</Compiler>
</Target>
<Target title="Release">
<Option output="bin/Release/DAA_QUICK_SORT" prefix_auto="1" extension_auto="1" />
<Option object_output="obj/Release/" />
<Option type="1" />
<Option compiler="gcc" />
<Compiler>
<Add option="-O2" />
</Compiler>
<Linker>
<Add option="-s" />
</Linker>
</Target>
</Build>
<Compiler>
<Add option="-Wall" />
<Add option="-fexceptions" />
</Compiler>
<Unit filename="main.cpp" />
<Extensions>
<lib_finder disable_auto="1" />
</Extensions>
</Project>
</CodeBlocks_project_file>
7 changes: 7 additions & 0 deletions DAA_QUICK_SORT/DAA_QUICK_SORT.depend
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# depslib dependency file v1.0
1643806793 source:c:\users\nasreen parween\desktop\new folder\daa_quick_sort\main.cpp
<iostream>
<limits.h>
<stdlib.h>
<fstream>

10 changes: 10 additions & 0 deletions DAA_QUICK_SORT/DAA_QUICK_SORT.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_layout_file>
<FileVersion major="1" minor="0" />
<ActiveTarget name="Debug" />
<File name="main.cpp" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
<Cursor>
<Cursor1 position="2292" topLine="80" />
</Cursor>
</File>
</CodeBlocks_layout_file>
20 changes: 20 additions & 0 deletions DAA_QUICK_SORT/QuickSort.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
No. of Elements (n),No. of Comparisions(count),n*n,n*log(n)
50,243,2500,282.1928095
100,628,10000,664.385619
150,1187,22500,1084.322804
200,1506,40000,1528.771238
250,2011,62500,1991.446071
300,2598,90000,2468.645607
350,3149,122500,2957.923889
400,3908,160000,3457.542476
450,4203,202500,3966.201536
500,4947,250000,4482.892142
550,5294,302500,5006.808295
600,5581,360000,5537.291214
650,6695,422500,6073.79234
700,7174,490000,6615.847778
750,7307,562500,7163.060089
800,8371,640000,7715.084952
850,8529,722500,8271.621176
900,8941,810000,8832.403072
950,9686,902500,9397.194518
Binary file added DAA_QUICK_SORT/bin/Debug/DAA_QUICK_SORT.exe
Binary file not shown.
110 changes: 110 additions & 0 deletions DAA_QUICK_SORT/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
#include <iostream>
#include<limits.h>
#include<stdlib.h>
#include<fstream>
using namespace std;
template <class t>
class QuickSort
{
t A[1000];
public:
t count ,n;
int input();
void Randomized_quick(t A[],int p, int r);
int Randomized_partition(t A[], int p,int r, int n);
int partition(t A[], int p, int r);
void display();
};
template <class t>
int QuickSort<t>::input()
{
count=0;
cout<<"ENTER THE NUMBER OF ELEMENTS IN AN ARRAY:"<<endl;
cin>>n;
for(int i=1; i<=n;i++)
{
A[i]=(rand()%1000)+1;
}
Randomized_quick(A,1,n);
}
template <class t>
int QuickSort<t>::partition(t A[],int p,int r)
{
int x,i,j,temp,temp2;
x=A[r];
i=p-1;
for(j=p; j<r; j++)
{
if(A[j]<=x)
{
i++;
temp=A[i];
A[i]=A[j];
A[j]=temp;
count++;
}
else{
count++;
}
}
temp2=A[i+1];
A[i+1]=A[r];
A[r]=temp2;
return (i+1);
}
template <class t>
void QuickSort<t> :: Randomized_quick(t A[], int p,int r)
{
int q;
if(p<r)
{
q=Randomized_partition(A,p,r,n);
Randomized_quick(A,p,q-1);
Randomized_quick(A,q+1,r);
}
}
template <class t>
int QuickSort<t> :: Randomized_partition(t A[], int p,int r, int n)
{
int i, temp;
i=p+rand()%(r-p+1);
temp=A[r];
A[r]=A[i];
A[i]=temp;
return partition(A,p,r);
}
template <class t>
void QuickSort<t>::display()
{
for(int i=1; i<=n; i++){
cout<<A[i]<<" ";
}
cout<<endl;
}
int main()
{
cout<<"....Quick SORT...."<<endl;
ofstream f("QuickSort.csv");
int c;
char ch='y';
while(ch=='y'||ch=='y')
{
QuickSort<int> q;
q.input();
cout<<"THE ELEMENT OF AN ARRAY BEFORE SORTING : "<<endl;
q.display();
cout<<"THE ELEMENT OF AN ARRAY AFTER SORTING :"<<endl;
q.display();
if(f)
{
f<<q.n<<","<<q.count;
f<<endl;
}
cout<<"THE NUMBER OF COMPARISIONS ARE:"<<q.count<<endl;
cout<<"\nDO YOU WANT TO CONTINUE?(y/n) :";
cin>>ch;
cout<<endl;
}
f.close();
return 0;
}
Binary file added DAA_QUICK_SORT/obj/Debug/main.o
Binary file not shown.

0 comments on commit 967990e

Please sign in to comment.