-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#include<iostream> | ||
#include "io.cpp" | ||
using namespace std; | ||
|
||
void concate(int x[],int n,int y[],int m, int z[]){ | ||
int i; | ||
for(i=0;i<n;i++) | ||
z[i]= x[i]; | ||
|
||
for(i=0;i<m;i++) | ||
z[n+i]= y[i]; | ||
} | ||
|
||
int main(){ | ||
int x[5],y[10],z[15]; | ||
cout<<"\n Enter Element of first Array "; | ||
input(x,5); | ||
cout<<"\n Enter element of second array "; | ||
input(y,10); | ||
|
||
concate(x,5,y,10,z); | ||
|
||
cout<<"\nFirst Array :"; | ||
output(x,5); | ||
cout<<"\n Second Array :"; | ||
output(y,10); | ||
cout<<"\n Concatenated Array :"; | ||
output(z,15); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#include<iostream> | ||
#include<iomanip> | ||
using namespace std; | ||
|
||
void input(int x[], int n){ | ||
for(int i=0;i<n;i++) | ||
{ | ||
cout<<"Enter "<<i<<" element :"; | ||
cin>>x[i]; | ||
} | ||
return; | ||
} | ||
|
||
void output(int x[], int n){ | ||
for(int i=0;i<n;i++) | ||
cout<<setw(6)<<x[i]; | ||
return; | ||
} | ||
|
||
void delete_element(int x[], int &m, int pos) | ||
{ | ||
if(m<=0){ | ||
cout<<"Array Empty. Can't' DELETE element"; | ||
} | ||
else | ||
{ | ||
for(int i=pos-1;i<m;i++) | ||
x[i]= x[i+1]; | ||
|
||
m = m-1; | ||
} | ||
return; | ||
} | ||
|
||
int main(){ | ||
int x[1000],m, pos; | ||
//input phase | ||
cout<<"Enter size of filled position :"; | ||
cin>>m; | ||
input(x,m); | ||
|
||
cout<<"\n Enter position that you want to delete :"; | ||
cin>>pos; | ||
|
||
//processing phase | ||
delete_element(x,m,pos); | ||
|
||
//output | ||
cout<<"\n\nArray after insertion \n"; | ||
output(x,m); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include<iostream> | ||
#include<iomanip> | ||
using namespace std; | ||
|
||
void insert_element(int x[],int n, int &front, int &rear, int value){ | ||
if(rear>=n-1){ | ||
cout<<"\n Queue full. Can not add another element"; | ||
} | ||
else{ | ||
if(rear == -999){ | ||
front = rear =0; | ||
x[rear]=value; | ||
} | ||
else{ | ||
rear = rear+1; | ||
x[rear]=value; | ||
} | ||
} | ||
} | ||
|
||
void delete_element(int x[], int &front, int &rear ){ | ||
if(front==-999){ | ||
cout<<"\n QUeue Empty.Can not delete element"; | ||
} | ||
else | ||
{ | ||
if(front==rear){ | ||
cout<<"Deleted element "<<x[front]; | ||
front = rear = -999; | ||
} | ||
else | ||
{ | ||
cout<<"Deleted element"<<x[front]; | ||
front = front+1; | ||
} | ||
} | ||
} | ||
|
||
void display(int x[],int front,int rear){ | ||
if(front==-999){ | ||
cout<<"\n Queue Empty"; | ||
} | ||
else{ | ||
for(int i=front;i<=rear;i++) | ||
cout<<setw(6)<<x[i]; | ||
} | ||
} | ||
|
||
int main(){ | ||
int x[10],front, rear,choice,value; | ||
front=rear = -999; | ||
do{ | ||
cout<<"\n\n QUEUE MENU"; | ||
cout<<"\n1. Add Element"; | ||
cout<<"\n2. Delete"; | ||
cout<<"\n3. Display"; | ||
cout<<"\n4. Exit"; | ||
cout<<"\n\n Enter your choice (1..4):"; | ||
cin>>choice; | ||
switch(choice){ | ||
case 1: | ||
cout<<"\n Enter value :"; | ||
cin>>value; | ||
insert_element(x,10,front,rear,value); | ||
break; | ||
case 2: | ||
delete_element(x,front,rear); | ||
break; | ||
case 3: | ||
display(x,front,rear); | ||
break; | ||
case 4: | ||
break; | ||
default: | ||
cout<<"\nWrong Choice....Try again"; | ||
} | ||
}while(choice!=4); | ||
return 0; | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// program to search an element from a list of elements using linear search method | ||
// Developed by : rakesh kumar | ||
|
||
|
||
#include<iostream> | ||
using namespace std; | ||
int linear_search(int x[],int n, int data) | ||
{ | ||
int found =0; | ||
for(int i=0;i<n;i++) | ||
if(x[i]==data) | ||
found =1; | ||
|
||
return found; | ||
} | ||
int main(){ | ||
int x[10],i,data,result; | ||
//input phase | ||
for(i=0;i<10;i++) | ||
{ | ||
cout<<"Enter x["<<i+1<<"] Element : "; | ||
cin>>x[i]; | ||
} | ||
cout<<"\n Enter element that you want to search :"; | ||
cin>>data; | ||
//processing phase | ||
result = linear_search(x,10,data); | ||
//output phase | ||
if(result ==0) | ||
cout<<"Element does not exists"; | ||
else | ||
cout<<"Element exist in this array"; | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#include<iostream> | ||
#include "io.cpp" | ||
using namespace std; | ||
|
||
void merge(int x[],int n,int y[],int m, int z[]){ | ||
int i,j,k; | ||
i=j=k=0; | ||
while(i<n && j<m){ | ||
if(x[i]<y[j]){ | ||
z[k]=x[i]; | ||
i++; | ||
k++; | ||
} | ||
else{ | ||
z[k]=y[j]; | ||
j++; | ||
k++; | ||
} | ||
} | ||
while(i<n){ | ||
z[k]=x[i]; | ||
i++; | ||
k++; | ||
} | ||
while(j<m){ | ||
z[k]=y[j]; | ||
j++; | ||
k++; | ||
} | ||
} | ||
|
||
int main(){ | ||
int x[5],y[10],z[15]; | ||
cout<<"\n Enter Element of first Array "; | ||
input(x,5); | ||
cout<<"\n Enter element of second array "; | ||
input(y,10); | ||
|
||
merge(x,5,y,10,z); | ||
|
||
cout<<"\nFirst Array :"; | ||
output(x,5); | ||
cout<<"\n Second Array :"; | ||
output(y,10); | ||
cout<<"\n Concatenated Array :"; | ||
output(z,15); | ||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
#include<iostream> | ||
#include<iomanip> | ||
using namespace std; | ||
|
||
void push(int x[],int n, int &m, int value){ | ||
if(m>=n){ | ||
cout<<"\n Stack full. Can not Push another element"; | ||
} | ||
else{ | ||
x[m]=value; | ||
m= m+1; | ||
} | ||
} | ||
|
||
void pop(int x[], int &m){ | ||
if(m<=0){ | ||
cout<<"\n Stack Empty.Can not Pop element"; | ||
} | ||
else | ||
{ | ||
cout<<"Popped Value :"<<x[m-1]; | ||
m= m-1; | ||
|
||
} | ||
} | ||
|
||
void display(int x[],int m){ | ||
if(m<=0){ | ||
cout<<"\n Stack Empty"; | ||
} | ||
else{ | ||
for(int i=0;i<m;i++) | ||
cout<<setw(6)<<x[i]; | ||
} | ||
} | ||
|
||
int main(){ | ||
int x[10],m,choice,value; | ||
m=0; | ||
do{ | ||
cout<<"\n\n STACK MENU"; | ||
cout<<"\n1. Push"; | ||
cout<<"\n2. Pop"; | ||
cout<<"\n3. Display"; | ||
cout<<"\n4. Exit"; | ||
cout<<"\n\n Enter your choice (1..4):"; | ||
cin>>choice; | ||
switch(choice){ | ||
case 1: | ||
cout<<"\n Enter value :"; | ||
cin>>value; | ||
push(x,10,m,value); | ||
break; | ||
case 2: | ||
pop(x,m); | ||
break; | ||
case 3: | ||
display(x,m); | ||
break; | ||
case 4: | ||
break; | ||
default: | ||
cout<<"\nWrong Choice....Try again"; | ||
} | ||
}while(choice!=4); | ||
return 0; | ||
} |