-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b634921
commit 1932ea5
Showing
7 changed files
with
181 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> | ||
<CodeBlocks_project_file> | ||
<FileVersion major="1" minor="6" /> | ||
<Project> | ||
<Option title="DAA_MERGE_SORT" /> | ||
<Option pch_mode="2" /> | ||
<Option compiler="gcc" /> | ||
<Build> | ||
<Target title="Debug"> | ||
<Option output="bin/Debug/DAA_MERGE_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_MERGE_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 /> | ||
</Project> | ||
</CodeBlocks_project_file> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# depslib dependency file v1.0 | ||
1642052461 source:c:\users\nasreen parween\desktop\new folder\daa_merge_sort\main.cpp | ||
<iostream> | ||
<fstream> | ||
<stdlib.h> | ||
|
This file contains 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
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="2000" topLine="75" /> | ||
</Cursor> | ||
</File> | ||
</CodeBlocks_layout_file> |
Binary file not shown.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
template <class t> | ||
class msort | ||
{ | ||
|
||
public: | ||
t a[1000]; | ||
int count; | ||
int n; | ||
void input(); | ||
void display(); | ||
t mergesort(t a[], int p, int r); | ||
void Merge(t a[],int p, int q,int r); | ||
}; | ||
template <class t> | ||
void msort<t>:: input() | ||
{ | ||
int i; | ||
cout<<"\n ENTER THE NUMBER OF ELEMENTS :"<<endl; | ||
cin>>n; | ||
for(i=1;i<=n;i++) | ||
a[i]=rand()%100; | ||
} | ||
template <class t> | ||
void msort<t>::display() | ||
{ | ||
for(int i=1;i<=n;i++) | ||
cout<<a[i]<<" "; | ||
} | ||
template <class t> | ||
t msort<t>:: mergesort(t a[],int p, int r) | ||
{ | ||
if(p<r) | ||
{ | ||
int q=(p+r-1)/2; | ||
mergesort(a,p,q); | ||
mergesort(a,q+1,r); | ||
Merge(a,p,q,r); | ||
|
||
} | ||
return count; | ||
} | ||
template <class t> | ||
void msort<t>:: Merge(t a[], int p, int q, int r) | ||
{ | ||
int i,j; | ||
int n1=q-p+1; | ||
int n2=r-q; | ||
t L[500] , R[500]; | ||
for(i=1;i<=n;i++) | ||
L[i]=a[p+i-1]; | ||
for(j=1; j<=n;j++) | ||
R[j]=a[q+j]; | ||
L[n1+1]=INT_MAX; | ||
R[n2+1]=INT_MAX; | ||
i=j=1; | ||
for(int k=p; k<=r; k++) | ||
{ | ||
if(L[i]<=R[j]) | ||
{ | ||
a[k]=L[i]; | ||
i++; | ||
} | ||
else | ||
{ | ||
a[k]=R[j]; | ||
j++; | ||
} | ||
count++; | ||
} | ||
} | ||
int main() | ||
{ | ||
ofstream f("mergesort.csv"); | ||
int c; | ||
char ch='y'; | ||
while(ch=='y'||ch=='y') | ||
{ | ||
msort<int>m; | ||
|
||
m.input(); | ||
cout<<"\n THE ELEMENT OF AN ARRAY ARE :"; | ||
m.display(); | ||
m.count=0; | ||
c=m.mergesort(m.a,1,m.n); | ||
cout<<"\n AFTER SORTHING THE ELEMENTS ARE:"<<endl; | ||
m.display(); | ||
if(f) | ||
{ | ||
f<<m.n<<","<<c; | ||
f<<endl; | ||
} | ||
cout << "\n THE NUMBER OF COMPARISIONS ARE :" << c; | ||
cout<<"\n DO YOU WANT TO CONTINUE ? (y/n) "; | ||
cin>>ch; | ||
} | ||
cout<<"\n NUMBER OF COMPARISIONS :"<<c; | ||
f.close(); | ||
|
||
return 0; | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
No. of Elements (n),No. of Comparisions (count),n*n,log(n) | ||
30,148,900,4.906890596 | ||
50,286,2500,5.64385619 | ||
70,432,4900,6.129283017 | ||
90,592,8100,6.491853096 | ||
110,752,12100,6.781359714 | ||
130,914,16900,7.022367813 | ||
150,1094,22500,7.22881869 | ||
170,1274,28900,7.409390936 | ||
190,1454,36100,7.569855608 | ||
210,1634,44100,7.714245518 | ||
230,1814,52900,7.845490051 | ||
250,1994,62500,7.965784285 | ||
270,2188,72900,8.076815597 | ||
290,2388,84100,8.17990909 | ||
310,2588,96100,8.276124405 | ||
330,2788,108900,8.366322214 | ||
350,2988,122500,8.451211112 | ||
370,3188,136900,8.531381461 | ||
390,3388,152100,8.607330314 | ||
410,3588,168100,8.6794801 | ||
430,3788,184900,8.74819285 |
Binary file not shown.