Data Structure (CLG)
Data Structure (CLG)
#Bubble Sort:-
// Online C++ compiler to run C++ program online
#include <iostream>
#include<stdio.h>
using namespace std;
int main() {
int n, c, d, temp;
cout<<"Enter the no of element you like to enter in the array : ";
cin>>n;
int ar[n + 1];
for(int i = 0;i < n;i++)
{
cout<<"Enter the element of index "<<i<<": ";
cin>>ar[i];
}
for(c = 0; c < n; c++)
{
for(d = 0;d < n - c-1;d++)
{
if(ar[d] > ar[d+1])
{
temp = ar[d];
ar[d] = ar[d+1];
ar[d+1] = temp;
}
}
}
for(int i = 0;i < n;i++)
{
cout<<ar[i]<<endl;
return 0;
}
--------------------------------------------------------------
PROGRAM TO ADD 2 NO:
#include<iostream>
using namespace std;
void PUSH();
void POP();
void DISPLAY();
int stack[5];
int Top=-1;
int main ()
{
int ch;
do
{
printf("\n1. Push \n2. POP \n3. DISPLAY \n4. EXIT");
printf("\nENTER UR CHOICE\n\n");
scanf("%d",&ch);
switch(ch)
{
case 1: PUSH();
break;
case 2: POP();
break;
case 3: DISPLAY();
break;
}
}while(ch!=4);
return 0;
}
void PUSH()
{
int item;
if(Top==Max-1)
{
printf("\nOVERFLOW\n");
}
else
{
printf("\nENTER THE VALUE U WANT TO PUSH\n");
scanf("%d",&item);
printf("\n");
Top=Top+1;
stack[Top]=item;
}
}
void POP()
{
int item;
if (Top==-1)
{
printf("\nUNDERFLOW\n");
}
else
{
item=stack[Top];
Top=Top-1;
printf("\nTHE DELETED ITEM FROM THE STACK IS %d\n\n",item);
}
}
void DISPLAY()
{
int i;
if(Top==-1)
{
printf("\nUNDERFLOW\n");
}
else
{
printf("\nStack ELEMENT ARE--->\n");
for(i=Top;i>=0;i--)
{
printf("\n %d\n",stack[i]);
}
printf("\n");
}
}
-------------------------------------------------------------------------------