Linear Sort in DSA C++

Program 1

// Linear Sort 
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
    system("cls");
    int ar[500],n,i,j,temp;
    cout<<"\n Enter the limit: ";
    cin>>n;
    cout<<"\n Enter elements in array: ";
    for(i=0;i<n;i++)
      cin>>ar[i];
    // sorting 
    for(i=0;i<n;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(ar[j]<ar[i])
            {
                temp=ar[i];
                ar[i]=ar[j];
                ar[j]=temp;
            }
        }
    }  
     cout<<"\n Sorted elements : "  ;
     for(i=0;i<n;i++)
     cout<<"\n"<<ar[i];
    
    return 0;
}

 

courses
Image

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *