Skip to content

Commit

Permalink
practice question
Browse files Browse the repository at this point in the history
  • Loading branch information
NasreenParween committed Jun 29, 2022
0 parents commit 07484e4
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 0 deletions.
40 changes: 40 additions & 0 deletions DAA_BUBBLE_SORT/DAA_BUBBLE_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_BUBBLE_SORT" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/DAA_BUBBLE_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_BUBBLE_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>
6 changes: 6 additions & 0 deletions DAA_BUBBLE_SORT/DAA_BUBBLE_SORT.depend
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# depslib dependency file v1.0
1642604908 source:c:\users\nasreen parween\desktop\new folder\daa_bubble_sort\main.cpp
<iostream>
<fstream>
<stdlib.h>

10 changes: 10 additions & 0 deletions DAA_BUBBLE_SORT/DAA_BUBBLE_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="1109" topLine="33" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file added DAA_BUBBLE_SORT/bin/Debug/DAA_BUBBLE_SORT.exe
Binary file not shown.
20 changes: 20 additions & 0 deletions DAA_BUBBLE_SORT/bubbleSort.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
No. of Elements(n),No. of Comparision (count),n*n,n*logn
30,420,900,147.2067179
50,1224,2500,282.1928095
70,2379,4900,429.0498112
90,3869,8100,584.2667787
110,5940,12100,745.9495685
130,8349,16900,912.9078157
150,11169,22500,1084.322804
170,13959,28900,1259.596459
190,17889,36100,1438.272566
210,21792,44100,1619.991559
230,26307,52900,1804.462712
250,31115,62500,1991.446071
270,36015,72900,2180.740211
290,41470,84100,2372.173636
310,47817,96100,2565.598566
330,54165,108900,2760.886331
350,60984,122500,2957.923889
370,68259,136900,3156.61114
390,75152,152100,3356.858822
81 changes: 81 additions & 0 deletions DAA_BUBBLE_SORT/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#include<iostream>
#include<fstream>
#include<stdlib.h>
using namespace std;
template <class t>
class bsort
{
public:
t a[500];
t n;
void input();
void display();
int sort();
};
template <class t>
void bsort<t>::input()
{
int i;
cout<<"\nEnter the number of elements:";
cin>>n;
for(i=1;i<=n;i++)
a[i]=rand()%100;
}
template <class t>
void bsort<t>::display()
{
for(int i=1;i<=n;i++)
cout<<a[i]<<" ";
}
template <class t>
int bsort<t>::sort()
{
int temp,i,j,swap,count=0;
for(i=1;i<=n;i++)
{
swap=0;
for(j=1;j<=(n-i);j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
swap=1;
}
count++;
}
if(swap==0)
{
break;
}
}
cout<<"\nArray after Sorting : ";
display();
cout<<"\nThe number of Comparisons are : "<<count;
return count;
}
int main()
{
ofstream f("bubbleSort.csv");
int c;
char ch='y';
while(ch=='y'||ch=='Y')
{
bsort<int> i;
i.input();
cout<<"\nElements of Array are : ";
i.display();
c=i.sort();
if(f)
{
f<<i.n<<","<<c;
f<<endl;
}
cout<<"\nDo you wish to continue(y/n) : ";
cin>>ch;
}
f.close();
return 0;
}

Binary file added DAA_BUBBLE_SORT/obj/Debug/main.o
Binary file not shown.

0 comments on commit 07484e4

Please sign in to comment.