Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cpp codes for selection sort and topological sort #99

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,8 @@
- Place: Chennai, India
- Bio: 3rd year CSE student at SRM university
- Github: [Sitzz23](https://github.com/Sitzz23)

#### Name: [Harshit Mittal](https://github.com/CodeWizard16)
- Place: Delhi, India
- Bio: Computer Science undergrad at Netaji Subhas University of Technology, Delhi, India
- GitHub: [Harshit Mittal](https://github.com/CodeWizard16)
47 changes: 47 additions & 0 deletions Sorting/Cpp/selectionsort.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#include<iostream.h>
using namespace std;
int selection(int[],int);
int minimum(int *a,int n,int &min,int i)
{
int j;
for(j=i+1;j<n;j++)
{
if(a[j]<a[min])
{
min=j;
}
}
}

int main()
{
int a[100],n,i;
cout<<"ENTER NUMBER OF ITEMS: ";
cin>>n;

for(i=0;i<n;i++)
{
cout<<"ENTER ITEM "<<i+1<<":";
cin>>a[i];
}

selection(a,n);

cout<<"SORTED DATA"<<endl;
for(i=0;i<n;i++)
{
cout<<a[i]<<" ";
}
}

int selection(int *A,int N)
{
int i,min;

for(i=0;i<N-1;i++)
{
min=i;
minimum(A,N,min,i);
swap(A[i],A[min]);
}
}
Loading