Index S.N o. Name of Program Pg. No Remarks 1. WAP for one dimensional (1D) array. 1-1 2. WAP for two dimensional (2D) array. 2-2 3. WAP for linear search. 3-5 4. WAP for binary search. 6-7 5. WAP for insertion. 8-9 6. WAP for deletion. 10-11 7. WAP for sorting. 12-13 8. WAP which can perform all the operations of array. 14-18 9. WAP to demonstrate the use of stack (linear array) in converting arithmetic expression from infix notation to postfix notation. 19-24 10. WAP to demonstrate various operations on linear queue using linear array. 25-27 11. WAP to demonstrate various operations on circular queue using linear array. 28-32 12. WAP to sort array of integers using bubble sort. 33-34 13. WAP to sort array of integers using insertion sort. 35-36 14. WAP to sort array of integers using merge sort. 37-39 15. WAP to sort array of integers using quick sort. 40-41 16. WAP to traverse a linked list. 42-43 17. WAP to insert an element in a linked list. 44-47 18. WAP to delete an element in a linked list. 48-51 19. WAP to search an element in a linked list. 52-54
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Index
S.No. Name of Program Pg. No Remarks
1. WAP for one dimensional (1D) array. 1-1
2. WAP for two dimensional (2D) array. 2-2
3. WAP for linear search. 3-5
4. WAP for binary search. 6-7
5. WAP for insertion. 8-9
6. WAP for deletion. 10-11
7. WAP for sorting. 12-13
8. WAP which can perform all the operations of array. 14-18
9.WAP to demonstrate the use of stack (linear array) in converting arithmetic expression from infix notation to postfix notation.
19-24
10. WAP to demonstrate various operations on linear queue using linear array. 25-27
11. WAP to demonstrate various operations on circular queue using linear array. 28-32
12. WAP to sort array of integers using bubble sort. 33-34
13. WAP to sort array of integers using insertion sort. 35-36
14. WAP to sort array of integers using merge sort. 37-39
15. WAP to sort array of integers using quick sort. 40-41
16. WAP to traverse a linked list. 42-43
17. WAP to insert an element in a linked list. 44-47
18. WAP to delete an element in a linked list. 48-51
19. WAP to search an element in a linked list. 52-54
20. WAP of shell sort. 55-57
12
DSPM Lab BTCS-306
1. WAP for one dimensional (1D) array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10],n,i;
cout<<"Enter the no.elements in array"<<endl;
cin>>n;
cout<<"Enter diffrent array's element\n";
for(i=1;i<=n;i++)
{
cin>>a[i];
}
cout<<"\nArray elements are:-\n";
for(i=1;i<=n;i++)
cout<<a[i];
getch();
}
12
DSPM Lab BTCS-306
2. WAP for two dimensional(2D) array.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[10][10],n,m,i,j;
cout<<"\nEnter the no. of rows and columns of matrix:\n ";
cin>>m>>n;
cout<<"\nEnter the array element\n";
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
cin>>a[i][j];
}
}
cout<<"\nEntered matrix is";
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
cout<<"\t"<<a[i][j];
}
cout<<"\n";
12
DSPM Lab BTCS-306
}
getch();
}
12
DSPM Lab BTCS-306
3. WAP for linear search.
#include<iostream.h>
#include<conio.h>
int Lsearch(int[],int,int);
void main()
{
int ar[50],item,n,index;
cout<<"Enter the array";
cin>>n;
cout<<"\nEnter array element\n";
for(int i=0;i<n;i++)
{
cin>>ar[i];
}
cout<<"\nEnter element to be searched for..";
cin>>item;
index=Lsearch(ar,n,item);
if(index==-1)
cout<<"given element could not found";
else
cout<<"Element found at index: "<<index<<"position: "<<index+1<<endl;
}
int Lsearch(int ar[],int size,int item)
{
for(int i=0;i<size;i++)
12
DSPM Lab BTCS-306
{
if(ar[i]==item)
return i;
}
return-1;
}
12
DSPM Lab BTCS-306
4. WAP for binary search.
#include<iostream.h>
#include<conio.h>
int Bsearch(int[],int,int);
void main()
{
int ar[50],item,n,index;
cout<<"enter the size of array";
cin>>n;
cout<<"\nEnter the array's element(must be sorted in asc order)\n";
for(int i=0;i<=n;i++)
cin>>ar[i];
cout<<"\nEnter element to be search for...";
cin>>item;
index=Bsearch(ar,n,item);
if(index==-1)
cout<<"\ngiven element could not be found\n";
else
cout<<"\nElement found at index:"<<index<<",position:"<<index+1<<endl;
}
int Bsearch(int ar[],int size,int item)
{
int beg,last,mid;
beg=0; last=size-1;
while(beg<=last)
12
DSPM Lab BTCS-306
{
mid=(beg+last)/2;
if(item==ar[mid]) return mid;
else if(item>ar[mid]) beg=mid+1;
else last=mid-1;
}
return-1;
}
12
DSPM Lab BTCS-306
5. WAP for insertion.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20],n,k,i,item;
void insert(int a[],int n,int k,int item);
cout<<"Enter the no.of element";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter the element a["<<i<<"]=";
cin>>a[i];
}
cout<<"Enter item to be inserted";
cin>>item;
cout<<"Enter index position for the new item";
cin>>k;
insert(a,k,n,item);
cout<<"Enter element after insertion\n";
for(i=0;i<n;i++)
cout<<" "<<a[i];
getch();
}
12
DSPM Lab BTCS-306
void insert(int a[],int n,int k,int item)
{
int i=n-1;
while(i>=k)
{
a[i+1]=a[i];
i=i-1;
}
a[k]=item;
n=n+1;
}
12
DSPM Lab BTCS-306
6. WAP for deletion.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20],n,k,item;
void delete1(int a[],int&n,int k);
cout<<"Enter no. of element";
cin>>n;
for(int i=0;i<n;i++)
{
cout<<"Enter element a["<<i<<"]=";
cin>>a[i];
}
cout<<"Enter the postion of element we want to delete";
cin>>k;
delete1(a,n,k-1);
cout<<"\nElement after deletion\n";
for(i=0;i<n;i++)
cout<<a[i];
getch();
}
void delete1(int a[],int&n,int i)
{
12
DSPM Lab BTCS-306
for(int k;i<=n-2;i++)
a[i]=a[i+1];
n=n-1;
}
12
DSPM Lab BTCS-306
7. WAP for sorting.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int a[20],n,i;
void sort(int a[],int n);
cout<<"\nEnterno.of element\n";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"Enter element a["<<i<<"]=";
cin>>a[i];
}
sort(a,n);
cout<<"sorted element..";
for(i=0;i<n;i++)
{
cout<<a[i]<<"<";
}
getch();
}
void sort(int a[],int n)
{
12
DSPM Lab BTCS-306
int temp;
for(int i=0;i<n;i++)
{
for(int j=0;j<=n-i-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
12
DSPM Lab BTCS-306
8. WAP which can perform all the operations of array.