Skip to content

Commit

Permalink
insertion sort
Browse files Browse the repository at this point in the history
  • Loading branch information
NasreenParween committed Jul 2, 2022
1 parent 9fe98eb commit b634921
Show file tree
Hide file tree
Showing 9 changed files with 132 additions and 0 deletions.
40 changes: 40 additions & 0 deletions DAA_INSERSTION_SORT/DAA_INSERSTION_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_INSERSTION_SORT" />
<Option pch_mode="2" />
<Option compiler="gcc" />
<Build>
<Target title="Debug">
<Option output="bin/Debug/DAA_INSERSTION_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_INSERSTION_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_INSERSTION_SORT/DAA_INSERSTION_SORT.depend
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# depslib dependency file v1.0
1642004338 source:c:\users\nasreen parween\desktop\new folder\daa_inserstion_sort\main.cpp
<iostream>
<fstream>
<stdlib.h>

10 changes: 10 additions & 0 deletions DAA_INSERSTION_SORT/DAA_INSERSTION_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="1231" topLine="46" />
</Cursor>
</File>
</CodeBlocks_layout_file>
Binary file not shown.
Empty file.
76 changes: 76 additions & 0 deletions DAA_INSERSTION_SORT/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std;

template <class t>
class isort
{
public:
t a[500];
t n;
void input();
void display();
int Sort();
};
template <class t>
void isort<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 isort<t> :: display()
{
for(int i=1; i<=n; i++)
cout<<a[i]<<" ";
}
template<class t>
int isort<t>:: Sort()
{
int i,j,key,count=0;
for(j=2; j<=n; j++)
{
key=a[j];
i=j-1;
while(i>0&&a[i]>key)
{
a[i+1]=a[i];
i--;
count++;
}
count++;
a[i+1]=key;

}
cout<<"\nTHE ARRAY AFTER SORTING:";
display();
cout<<"\nTHE NUMBER OF COMARISIONS ARE :"<<count;
return count;
}
int main()
{
ofstream f("insertionSort.csv");
int c;
char ch='y';
while(ch=='y'||ch=='Y')
{
isort<int>i;
i.input();
cout<<"THE ELEMENTS OF AN ARRAY ARE :"<<endl;
i.display();
c=i.Sort();
if(f)
{
f<<i.n<<","<<c;
f<<endl;
}
cout<<"\n...Do you want to continue ?(y/n)..."<<endl;
cin>>ch;
}
f.close();
return 0;
}
Binary file added DAA_INSERSTION_SORT/main.exe
Binary file not shown.
Binary file added DAA_INSERSTION_SORT/main.o
Binary file not shown.
Binary file added DAA_INSERSTION_SORT/obj/Debug/main.o
Binary file not shown.

0 comments on commit b634921

Please sign in to comment.