SlideShare a Scribd company logo
1 of 14
/* WAP in C++ to perform basic operations on 1-D arrays .*/
#include<iostream.h>
#include<limits.h>
#include<process.h>
#include<conio.h>
/*--------------------------------------------------------------Functiondeclaration -------------------------------------------------------*/
intlinear_search(intA[ ],intn,intp);
voidbinary_search(intA[ ],intn,intp);
voidselection_sort(intA[ ],intn);
voidbubble_sort(intA[ ],intn);
voidinsertion_sort(intA[ ],intn);
voidmerge(intlow,intmid,inthigh);
voidmerge_sort(intlow,inthigh);
voidmerging(intA[],intB[],intn,intm,char c);
voidinsert_element(intA[],intn);
voiddelete_element(intA[],intn);
intA[50],n,mg=0;// global variable
/*--------------------------------------------------------------- Main'sbody ----------------------------------------------------------------------*/
voidmain()
{clrscr();
intch,o=0,h=0,t=0,k,m;
intB[50],p,subscript;
char choice;
cout<<"Enter the Size of array : ";
cin>>n;
cout<<"nnEnterthe elements: nn";
for(inti=0;i<n; i++)
cin>>A[i];
cout<<"nnArrayformedis : ";
for(i=0;i<n; i++)
cout<<A[i]<<"";
do{
lm:
cout<<"nnnnChoose fromthe following:";
cout<<"nnn1.Searchelementinanarray ";
cout<<"nn2.Sort the array ";
cout<<"nn3.Merge twoarrays ";
cout<<"nn4.Insertelementinarray ";
cout<<"nn5.Delete elementinarray ";
cout<<"nn6.Exit";
cout<<"nnnEnteryourchoice :";
cin>>ch;
switch(ch)
{
case 1 : l:
cout<<"nnt1.Linearsearch";
cout<<"nnt2.Binarysearch";
cout<<"nntEnteryourchoice :";
cin>>ch;
switch(ch)
{
case 1 : cout<<"nnEnterelementtobe searched:";
cin>>p;
subscript=linear_search(A,n,p);
if(subscript==-1)
cout<<"nnRequestedelementnotfound.";
else
cout<<"nnSearchSuccessful.";
cout<<"nnnThe requestedelementis"<<p<<". nnSubscript="<<subscript<<"nPosition
inarray = "<<subscript+1;
break;
case 2 : cout<<"nnEnterelementtobe searched:";
cin>>p;
binary_search(A,n,p);break;
default:cout<<"nnPleaseenterdesiredkeyword.";
goto l;
}
break;
case 2 : k:
cout<<"nnt1.SelectionSort ";
cout<<"nnt2.Bubble Sort";
cout<<"nnt3.Insertionsort";
cout<<"nnt4.Merge Sort";
cout<<"nntEnteryourchoice :";
cin>>ch;
switch(ch)
{
case 1 : if(o==1)
cout<<"nnArrayalreadysortedusingSelectionsort";
else
{if(h==0&&t==0)
{
selection_sort(A,n);
cout<<"nnnnSortedarrayis: nn";
for(k=0;k<n; k++)
cout<<A[k]<<"";
o=1;
}
else if(h==1&&t==0)
cout<<"nnArrayalreadysortedusingBubble sort";
else
cout<<"nnArrayalreadysortedusingInsertionsort";
}
break;
case 2 : if(h==1)
cout<<"nnArrayalreadysortedusingInsertionsort";
else
{if(o==0&&t==0)
{ bubble_sort(A,n);
cout<<"nnnnSortedarrayis: nn";
for( k=0; k<n; k++)
cout<<A[k]<<"";
h=1;
}
else if(t==1&&o==0)
cout<<"nnArrayalreadysortedusingInsertionsort";
else
cout<<"nnArrayalreadysortedusingSelectionsort";
}
break;
case 3: if(t==1)
cout<<"nnArrayalreadysortedusingInsertionsort";
else
{
if(h==0&&o==0)
{
insertion_sort(A,n);
t=1;
}
else if(h==1&&o==0)
cout<<"nnArrayalreadysortedusingBubble sort";
else
cout<<"nnArray alreadysortedusingselectionsort";
}
break;
case 4 : merge_sort(0,n);
cout<<"nnArrayaftermerge sort: nn";
for(intz=1; z<=n; z++)
cout<<A[z]<<" ";
break;
default:cout<<"nnPleaseenterdesiredkeyword.";
goto k;
}
break;
case 3: cout<<"nnEntersize of secondarray: ";
cin>>m;
for(i=0;i<m; i++)
cin>>B[i];
cout<<"nnFirstarray: nn";
for(i=0;i<n; i++)
cout<<A[i]<<"";
cout<<"nnSecondarray: nn";
for(i=0;i<m; i++)
cout<<B[i]<<"";
m:
cout<<"nnt1.Merge in ascendingorder";
cout<<"nnt2.Merge in descendingorder";
cout<<"nntEnteryourchoice : ";
cin>>ch; mg=1;
switch(ch)
{
case 1: merging(A,B,n,m,'a');break;
case 2: merging(A,B,n,m,'d');break;
default:cout<<"nnEnterValidkeyword";
goto m;
}
break;
case 4: insert_element(A,n);
break;
case 5: delete_element(A,n);break;
case 6: exit(0);break;
default:cout<<"nnPleaseenterdesiredkeyword:";
goto lm;
}
cout<<"nnWantto choose frommenuagain: ";
cin>>choice;
}while(choice=='y'||choice=='Y');
getch();
} // endof main
/*----------------------------------------------------------- FunctionDefinitions --------------------------------------------------------------*/
intlinear_search(intA[],intn,intp) //functiondefinition
{for(inti=0;i<n; i++)
{if (A[i]==p)
returni;
}
return-1;
}
voidbinary_search(intA[],intn,intp)
{ intL,U,mid; char ch;
lb: L=0; U=n-1;
while(L<=U) //i.e loopwill continue if L<=u.if L>U loopwill end
{ mid=(L+U)/2;
if(A[mid]==p)
{ cout<<"nnElement"<<p<<"found.SearchSuccessful.";
cout<<"nnSubscript="<<mid<<" nnPosition="<<mid+1;
break;
}
else if(p<=A[mid])
U=mid-1;
else
L=mid+1;
}//endof while loop
if(L>U)
{cout<<"nnUnsuccessful search.";
cout<<"nnnnWanttosearchagain.: "; cin>>ch;
if(ch=='y'||ch=='Y')
{cout<<"nnnnEnterthe elementtobe searched:";
cin>>p;
goto lb;}
else
exit(1);
}
}
voidselection_sort(intA[],intn)
{intsmall; int k,count=0;
for(inti=0;i<n; i++)
{ small=A[i]; count++;
for(intj=i+1;j<n; j++)
{
if(A[j]<small)
{small=A[j];
A[j]=A[i];
A[i]=small;
}
}
if(mg==0)
{
cout<<"nnArrayafteriteration"<<count<<"is:nn";
for(k=0;k<n; k++)
cout<<A[k]<<"";
}
}
}
voidbubble_sort(intA[],intn)
{ inttemp;intcount=0;
for(inti=0;i<n; i++)
{
for(intj=0; j<n-1;j++)
{ if(A[j+1]<A[j])
{ count++;
temp=A[j+1];
A[j+1]=A[j];
A[j]=temp;
cout<<"nnArrayforiteration"<<count<<" is: nn";
for(intk=0; k<n; k++)
cout<<A[k]<<"";
}
}
}
}
voidinsertion_sort(intA[],intn)
{intj,t;
A[n]=0;
for(inti=n;i>=0; i--) //shiftingeachelementtoitssuccesive position
A[i]=A[i-1];
A[0]=INT_MIN;// INT_MIN= -32768
for(i=1;i<=n; i++)
{ t=A[i];
j=i-1;
while(t<A[j])
{
A[j+1]=A[j];
j--;
}
A[j+1]=t;
cout<<"nnArrayafteriteration"<<i<<"=> nn";
for(intk=1; k<=n; k++)
cout<<A[k]<<"";
cout<<"nn";
}
cout<<"nnnSortedarrayis: nn";
for(intk=1; k<=n; k++)
cout<<A[k]<<"";
}
voidmerge_sort(intlow,inthigh)
{
int mid;
if(low<high)
{
mid=(low+high)/2;
merge_sort(low,mid);
merge_sort(mid+1,high);
merge(low,mid,high);
}
}
voidmerge(intlow,intmid,inthigh)
{
int h,i,j,b[50],k;
h=low;
i=low;
j=mid+1;
while((h<=mid)&&(j<=high))
{
if(A[h]<=A[j])
{
b[i]=A[h];
h++;
}
else
{
b[i]=A[j];
j++;
}
i++;
}
if(h>mid)
{
for(k=j;k<=high;k++)
{
b[i]=A[k];
i++;
}
}
else
{
for(k=h;k<=mid;k++)
{
b[i]=A[k];
i++;
}
}
for(k=low;k<=high;k++) A[k]=b[k];
}
voidmerging(intA[],intB[],intn,intm,char cha)
{mg=1;
int c[80];
for(inti=0; i<n;i++)
{
c[i]=A[i];
}
for(i=0;i<m; i++)
{
c[n+i]=B[i];
}
int p=m+n;
switch(cha)
{ case 'a' : cout<<"nnArrayformedaftermerginginascendingorder: nn";
selection_sort(c,p);
for(inti=0;i<p; i++)
{
cout<<c[i]<<" ";
}
break;
case 'd' : cout<<"nnArrayformedaftermergingindescendingorder: nn";
selection_sort(c,p);
for(i=p-1;i>=0; i--)
{
cout<<c[i]<<"";
}
break;
}
}
voidinsert_element(intA[],intn)
{ intp,pos;charchoice;
do
{if(n>=50||n<1)
cout<<"nnArrayOverflow.";
else
cout<<"nnEnterelementalongwithitsposition: nn";
cout<<"Element="; cin>>p;
cout<<"nnPosition="; cin>>pos;
for(inti=n;i>=pos;i--)
{
A[i]=A[i-1];
}
n++;
A[n]=0;
A[pos-1]=p;
cout<<"nnArrayformed:";
for(i=0;i<n; i++)
cout<<A[i]<<"";
cout<<"nnWantto insertagain: "; cin>>choice;
}while(choice=='y'||choice=='Y');
}
voiddelete_element(intA[],intn)
{ intpos,flag=1;
char choice;
do{
l:
cout<<"nnnEnterpositionof elementtodeleteit:";
cin>>pos;
if(pos-1>n-1)
{
cout<<"nnInvalid ";
goto l;
}
else
for(inti=0; i<n;i++)
{
if(pos-1==i)
{flag=0;
for(intj=pos-1;j<n;j++)
{
A[j]=A[j+1];
}
n--;
}
}
if(flag)
{
cout<<"nnInvalid...Enteragain:";
goto l;
}
cout<<"nnnArrayformed:";
for( i=0; i<n;i++)
cout<<A[i]<<"";
cout<<"nnnWantto delete again: ";
cin>>choice;
}while(choice=='y'||choice=='Y');
}
Output:
Enter the Size of array : 5
Enter the elements:
1
3
2
4
0
Array formedis : 1 3 2 4 0
Choose fromthe following:
1. Search elementinanarray
2. Sort the array
3. Merge twoarrays
4. Insertelementinarray
5. Delete elementinarray
6. Exit
Enter yourchoice : 1
1. Linearsearch
2. Binary search
Enter yourchoice : 1
Enter elementtobe searched:4
SearchSuccessful.
The requestedelementis4.
Subscript= 3
Positioninarray= 4
Want to choose frommenuagain:Y
Choose fromthe following:
1. Search elementinanarray
2. Sort the array
3. Merge twoarrays
4. Insertelementinarray
5. Delete elementinarray
6. Exit
Enter yourchoice : 2
1. SelectionSort
2. Bubble Sort
3. Insertionsort
4. Merge Sort
Enter yourchoice : 2
Array foriteration1 is:
1 2 3 4 0
Array foriteration2 is:
1 2 3 0 4
Array foriteration3 is:
1 2 0 3 4
Array foriteration4 is:
1 0 2 3 4
Array foriteration5 is:
0 1 2 3 4
Sortedarray is :
0 1 2 3 4
Want to choose frommenuagain: Y
Choose fromthe following:
1. Search elementinanarray
2. Sort the array
3. Merge twoarrays
4. Insertelementinarray
5. Delete elementinarray
6. Exit
Enter yourchoice : 2
1. SelectionSort
2. Bubble Sort
3. Insertionsort
4. Merge Sort
Enter yourchoice : 4
Array aftermerge sort:
0 1 2 3 4
Want to choose frommenuagain:Y
Choose fromthe following:
1. Search elementinanarray
2. Sort the array
3. Merge twoarrays
4. Insertelementinarray
5. Delete elementinarray
6. Exit
Enter yourchoice : 3
Enter yourchoice : 3
Enter size of secondarray : 5
1
0
8
9
2
Firstarray :
1 3 2 4 0
Secondarray :
1 0 8 9 2
1. Merge inascendingorder
2. Merge indescendingorder
Enter yourchoice : 1
Array formedaftermerginginascendingorder:
0 0 1 1 2 2 3 4 8 9
Want to choose frommenuagain:Y
1. Seaarch elementinanarray
2. Sort the array
3. Merge twoarrays
4. Insertelementinarray
5. Delete elementinarray
6. Exit
Enter yourchoice : 4
Enter elementalongwithitsposition:
Element=6
Position=2
Array formed:1 6 3 2 4 0
Want to insertagain: n
Want to choose frommenuagain: y
Choose fromthe following:
1. Search elementinanarray
2. Sort the array
3. Merge twoarrays
4. Insertelementinarray
5. Delete elementinarray
6. Exit
Enter yourchoice : 5
Enter positionof elementto delete it:6
Invalid
Enter positionof elementtodelete it:5
Array formed:1 6 3 2
Want to delete again:N
Want to choose frommenuagain: y
Choose fromthe following:
1. Search elementinanarray
2. Sort the array
3. Merge twoarrays
4. Insertelementinarray
5. Delete elementinarray
6. Exit
Enter yourchoice : 6
1 d array

More Related Content

What's hot

DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)cruisercoder
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...ssuserd6b1fd
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...ssuserd6b1fd
 
The MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer TraceThe MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer Traceoysteing
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...ssuserd6b1fd
 
Solr facets and custom indices
Solr facets and custom indicesSolr facets and custom indices
Solr facets and custom indicescgmonroe
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveNaresha K
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語ikdysfm
 
Numeric Range Queries in Lucene and Solr
Numeric Range Queries in Lucene and SolrNumeric Range Queries in Lucene and Solr
Numeric Range Queries in Lucene and SolrVadim Kirilchuk
 
Grammatical Optimization
Grammatical OptimizationGrammatical Optimization
Grammatical Optimizationadil raja
 
Python Peculiarities
Python PeculiaritiesPython Peculiarities
Python Peculiaritiesnoamt
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
Elixir formatter Internals
Elixir formatter InternalsElixir formatter Internals
Elixir formatter InternalsPedro Medeiros
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...ssuserd6b1fd
 
Personal Perl 6 compiler
Personal Perl 6 compilerPersonal Perl 6 compiler
Personal Perl 6 compilerAndrew Shitov
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...ssuserd6b1fd
 

What's hot (20)

DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)DConf 2016 std.database (a proposed interface & implementation)
DConf 2016 std.database (a proposed interface & implementation)
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5  b...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 3 of 5 b...
 
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
Notes for C++ Programming / Object Oriented C++ Programming for MCA, BCA and ...
 
The MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer TraceThe MySQL Query Optimizer Explained Through Optimizer Trace
The MySQL Query Optimizer Explained Through Optimizer Trace
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 5 of 5 by...
 
Solr facets and custom indices
Solr facets and custom indicesSolr facets and custom indices
Solr facets and custom indices
 
Evolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and EffectiveEvolving with Java - How to remain Relevant and Effective
Evolving with Java - How to remain Relevant and Effective
 
Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語Haskellで学ぶ関数型言語
Haskellで学ぶ関数型言語
 
c programming
c programmingc programming
c programming
 
Numeric Range Queries in Lucene and Solr
Numeric Range Queries in Lucene and SolrNumeric Range Queries in Lucene and Solr
Numeric Range Queries in Lucene and Solr
 
Grammatical Optimization
Grammatical OptimizationGrammatical Optimization
Grammatical Optimization
 
Explain
ExplainExplain
Explain
 
Python Peculiarities
Python PeculiaritiesPython Peculiarities
Python Peculiarities
 
Trie Data Structure
Trie Data StructureTrie Data Structure
Trie Data Structure
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
Elixir formatter Internals
Elixir formatter InternalsElixir formatter Internals
Elixir formatter Internals
 
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
Notes for GNU Octave - Numerical Programming - for Students - 02 of 02 by aru...
 
Vcs16
Vcs16Vcs16
Vcs16
 
Personal Perl 6 compiler
Personal Perl 6 compilerPersonal Perl 6 compiler
Personal Perl 6 compiler
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
 

Similar to 1 d array

Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rathSANTOSH RATH
 
python-cheatsheets.pdf
python-cheatsheets.pdfpython-cheatsheets.pdf
python-cheatsheets.pdfKalyan969491
 
python-cheatsheets that will be for coders
python-cheatsheets that will be for coderspython-cheatsheets that will be for coders
python-cheatsheets that will be for coderssarafbisesh
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)mailmerk
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdff3apparelsonline
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Saket Pathak
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docxdavinci54
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfzJoshua Thijssen
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)Make Mannan
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLConnor McDonald
 
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ....NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...NETFest
 

Similar to 1 d array (20)

Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
Main ds manual
Main ds manualMain ds manual
Main ds manual
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
16-sorting.ppt
16-sorting.ppt16-sorting.ppt
16-sorting.ppt
 
python-cheatsheets.pdf
python-cheatsheets.pdfpython-cheatsheets.pdf
python-cheatsheets.pdf
 
python-cheatsheets that will be for coders
python-cheatsheets that will be for coderspython-cheatsheets that will be for coders
python-cheatsheets that will be for coders
 
Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)Data structure and algorithm.(dsa)
Data structure and algorithm.(dsa)
 
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdfUsing Arrays with Sorting and Searching Algorithms1) This program .pdf
Using Arrays with Sorting and Searching Algorithms1) This program .pdf
 
Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)Data Structure in C (Lab Programs)
Data Structure in C (Lab Programs)
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
Chapter 4
Chapter 4Chapter 4
Chapter 4
 
DS LAB RECORD.docx
DS LAB RECORD.docxDS LAB RECORD.docx
DS LAB RECORD.docx
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)Lab manual data structure (cs305 rgpv) (usefulsearch.org)  (useful search)
Lab manual data structure (cs305 rgpv) (usefulsearch.org) (useful search)
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Arrays 06.ppt
Arrays 06.pptArrays 06.ppt
Arrays 06.ppt
 
APEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQLAPEX Connect 2019 - array/bulk processing in PLSQL
APEX Connect 2019 - array/bulk processing in PLSQL
 
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ....NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
.NET Fest 2018. Дмитрий Иванов. Иммутабельные структуры данных в .NET: зачем ...
 
arrays
arraysarrays
arrays
 

Recently uploaded

Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgsaravananr517913
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfAsst.prof M.Gokilavani
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the weldingMuhammadUzairLiaqat
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitterShivangiSharma879191
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)Dr SOUNDIRARAJ N
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - GuideGOPINATHS437943
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionMebane Rash
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvLewisJB
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsSachinPawar510423
 

Recently uploaded (20)

Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfgUnit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
Unit7-DC_Motors nkkjnsdkfnfcdfknfdgfggfg
 
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdfCCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
CCS355 Neural Network & Deep Learning Unit II Notes with Question bank .pdf
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
welding defects observed during the welding
welding defects observed during the weldingwelding defects observed during the welding
welding defects observed during the welding
 
8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter8251 universal synchronous asynchronous receiver transmitter
8251 universal synchronous asynchronous receiver transmitter
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
UNIT III ANALOG ELECTRONICS (BASIC ELECTRONICS)
 
Transport layer issues and challenges - Guide
Transport layer issues and challenges - GuideTransport layer issues and challenges - Guide
Transport layer issues and challenges - Guide
 
US Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of ActionUS Department of Education FAFSA Week of Action
US Department of Education FAFSA Week of Action
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Work Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvvWork Experience-Dalton Park.pptxfvvvvvvv
Work Experience-Dalton Park.pptxfvvvvvvv
 
Vishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documentsVishratwadi & Ghorpadi Bridge Tender documents
Vishratwadi & Ghorpadi Bridge Tender documents
 

1 d array

  • 1. /* WAP in C++ to perform basic operations on 1-D arrays .*/ #include<iostream.h> #include<limits.h> #include<process.h> #include<conio.h> /*--------------------------------------------------------------Functiondeclaration -------------------------------------------------------*/ intlinear_search(intA[ ],intn,intp); voidbinary_search(intA[ ],intn,intp); voidselection_sort(intA[ ],intn); voidbubble_sort(intA[ ],intn); voidinsertion_sort(intA[ ],intn); voidmerge(intlow,intmid,inthigh); voidmerge_sort(intlow,inthigh); voidmerging(intA[],intB[],intn,intm,char c); voidinsert_element(intA[],intn); voiddelete_element(intA[],intn); intA[50],n,mg=0;// global variable /*--------------------------------------------------------------- Main'sbody ----------------------------------------------------------------------*/ voidmain() {clrscr(); intch,o=0,h=0,t=0,k,m; intB[50],p,subscript; char choice; cout<<"Enter the Size of array : "; cin>>n; cout<<"nnEnterthe elements: nn"; for(inti=0;i<n; i++) cin>>A[i]; cout<<"nnArrayformedis : "; for(i=0;i<n; i++) cout<<A[i]<<""; do{ lm: cout<<"nnnnChoose fromthe following:"; cout<<"nnn1.Searchelementinanarray "; cout<<"nn2.Sort the array "; cout<<"nn3.Merge twoarrays "; cout<<"nn4.Insertelementinarray "; cout<<"nn5.Delete elementinarray "; cout<<"nn6.Exit"; cout<<"nnnEnteryourchoice :"; cin>>ch;
  • 2. switch(ch) { case 1 : l: cout<<"nnt1.Linearsearch"; cout<<"nnt2.Binarysearch"; cout<<"nntEnteryourchoice :"; cin>>ch; switch(ch) { case 1 : cout<<"nnEnterelementtobe searched:"; cin>>p; subscript=linear_search(A,n,p); if(subscript==-1) cout<<"nnRequestedelementnotfound."; else cout<<"nnSearchSuccessful."; cout<<"nnnThe requestedelementis"<<p<<". nnSubscript="<<subscript<<"nPosition inarray = "<<subscript+1; break; case 2 : cout<<"nnEnterelementtobe searched:"; cin>>p; binary_search(A,n,p);break; default:cout<<"nnPleaseenterdesiredkeyword."; goto l; } break; case 2 : k: cout<<"nnt1.SelectionSort "; cout<<"nnt2.Bubble Sort"; cout<<"nnt3.Insertionsort"; cout<<"nnt4.Merge Sort"; cout<<"nntEnteryourchoice :"; cin>>ch; switch(ch) { case 1 : if(o==1) cout<<"nnArrayalreadysortedusingSelectionsort"; else {if(h==0&&t==0) { selection_sort(A,n); cout<<"nnnnSortedarrayis: nn"; for(k=0;k<n; k++) cout<<A[k]<<""; o=1; } else if(h==1&&t==0) cout<<"nnArrayalreadysortedusingBubble sort"; else cout<<"nnArrayalreadysortedusingInsertionsort"; } break; case 2 : if(h==1)
  • 3. cout<<"nnArrayalreadysortedusingInsertionsort"; else {if(o==0&&t==0) { bubble_sort(A,n); cout<<"nnnnSortedarrayis: nn"; for( k=0; k<n; k++) cout<<A[k]<<""; h=1; } else if(t==1&&o==0) cout<<"nnArrayalreadysortedusingInsertionsort"; else cout<<"nnArrayalreadysortedusingSelectionsort"; } break; case 3: if(t==1) cout<<"nnArrayalreadysortedusingInsertionsort"; else { if(h==0&&o==0) { insertion_sort(A,n); t=1; } else if(h==1&&o==0) cout<<"nnArrayalreadysortedusingBubble sort"; else cout<<"nnArray alreadysortedusingselectionsort"; } break; case 4 : merge_sort(0,n); cout<<"nnArrayaftermerge sort: nn"; for(intz=1; z<=n; z++) cout<<A[z]<<" "; break; default:cout<<"nnPleaseenterdesiredkeyword."; goto k; } break; case 3: cout<<"nnEntersize of secondarray: "; cin>>m; for(i=0;i<m; i++) cin>>B[i]; cout<<"nnFirstarray: nn"; for(i=0;i<n; i++) cout<<A[i]<<""; cout<<"nnSecondarray: nn"; for(i=0;i<m; i++) cout<<B[i]<<""; m: cout<<"nnt1.Merge in ascendingorder"; cout<<"nnt2.Merge in descendingorder"; cout<<"nntEnteryourchoice : ";
  • 4. cin>>ch; mg=1; switch(ch) { case 1: merging(A,B,n,m,'a');break; case 2: merging(A,B,n,m,'d');break; default:cout<<"nnEnterValidkeyword"; goto m; } break; case 4: insert_element(A,n); break; case 5: delete_element(A,n);break; case 6: exit(0);break; default:cout<<"nnPleaseenterdesiredkeyword:"; goto lm; } cout<<"nnWantto choose frommenuagain: "; cin>>choice; }while(choice=='y'||choice=='Y'); getch(); } // endof main /*----------------------------------------------------------- FunctionDefinitions --------------------------------------------------------------*/ intlinear_search(intA[],intn,intp) //functiondefinition {for(inti=0;i<n; i++) {if (A[i]==p) returni; } return-1; } voidbinary_search(intA[],intn,intp) { intL,U,mid; char ch; lb: L=0; U=n-1; while(L<=U) //i.e loopwill continue if L<=u.if L>U loopwill end { mid=(L+U)/2; if(A[mid]==p) { cout<<"nnElement"<<p<<"found.SearchSuccessful."; cout<<"nnSubscript="<<mid<<" nnPosition="<<mid+1; break; } else if(p<=A[mid]) U=mid-1; else L=mid+1; }//endof while loop if(L>U) {cout<<"nnUnsuccessful search."; cout<<"nnnnWanttosearchagain.: "; cin>>ch; if(ch=='y'||ch=='Y')
  • 5. {cout<<"nnnnEnterthe elementtobe searched:"; cin>>p; goto lb;} else exit(1); } } voidselection_sort(intA[],intn) {intsmall; int k,count=0; for(inti=0;i<n; i++) { small=A[i]; count++; for(intj=i+1;j<n; j++) { if(A[j]<small) {small=A[j]; A[j]=A[i]; A[i]=small; } } if(mg==0) { cout<<"nnArrayafteriteration"<<count<<"is:nn"; for(k=0;k<n; k++) cout<<A[k]<<""; } } } voidbubble_sort(intA[],intn) { inttemp;intcount=0; for(inti=0;i<n; i++) { for(intj=0; j<n-1;j++) { if(A[j+1]<A[j]) { count++; temp=A[j+1]; A[j+1]=A[j]; A[j]=temp; cout<<"nnArrayforiteration"<<count<<" is: nn"; for(intk=0; k<n; k++) cout<<A[k]<<""; } } } } voidinsertion_sort(intA[],intn) {intj,t; A[n]=0; for(inti=n;i>=0; i--) //shiftingeachelementtoitssuccesive position A[i]=A[i-1];
  • 6. A[0]=INT_MIN;// INT_MIN= -32768 for(i=1;i<=n; i++) { t=A[i]; j=i-1; while(t<A[j]) { A[j+1]=A[j]; j--; } A[j+1]=t; cout<<"nnArrayafteriteration"<<i<<"=> nn"; for(intk=1; k<=n; k++) cout<<A[k]<<""; cout<<"nn"; } cout<<"nnnSortedarrayis: nn"; for(intk=1; k<=n; k++) cout<<A[k]<<""; } voidmerge_sort(intlow,inthigh) { int mid; if(low<high) { mid=(low+high)/2; merge_sort(low,mid); merge_sort(mid+1,high); merge(low,mid,high); } } voidmerge(intlow,intmid,inthigh) { int h,i,j,b[50],k; h=low; i=low; j=mid+1; while((h<=mid)&&(j<=high)) { if(A[h]<=A[j]) { b[i]=A[h]; h++; } else { b[i]=A[j]; j++; } i++; } if(h>mid) { for(k=j;k<=high;k++) { b[i]=A[k];
  • 7. i++; } } else { for(k=h;k<=mid;k++) { b[i]=A[k]; i++; } } for(k=low;k<=high;k++) A[k]=b[k]; } voidmerging(intA[],intB[],intn,intm,char cha) {mg=1; int c[80]; for(inti=0; i<n;i++) { c[i]=A[i]; } for(i=0;i<m; i++) { c[n+i]=B[i]; } int p=m+n; switch(cha) { case 'a' : cout<<"nnArrayformedaftermerginginascendingorder: nn"; selection_sort(c,p); for(inti=0;i<p; i++) { cout<<c[i]<<" "; } break; case 'd' : cout<<"nnArrayformedaftermergingindescendingorder: nn"; selection_sort(c,p); for(i=p-1;i>=0; i--) { cout<<c[i]<<""; } break; } } voidinsert_element(intA[],intn) { intp,pos;charchoice; do {if(n>=50||n<1) cout<<"nnArrayOverflow."; else cout<<"nnEnterelementalongwithitsposition: nn"; cout<<"Element="; cin>>p; cout<<"nnPosition="; cin>>pos;
  • 8. for(inti=n;i>=pos;i--) { A[i]=A[i-1]; } n++; A[n]=0; A[pos-1]=p; cout<<"nnArrayformed:"; for(i=0;i<n; i++) cout<<A[i]<<""; cout<<"nnWantto insertagain: "; cin>>choice; }while(choice=='y'||choice=='Y'); } voiddelete_element(intA[],intn) { intpos,flag=1; char choice; do{ l: cout<<"nnnEnterpositionof elementtodeleteit:"; cin>>pos; if(pos-1>n-1) { cout<<"nnInvalid "; goto l; } else for(inti=0; i<n;i++) { if(pos-1==i) {flag=0; for(intj=pos-1;j<n;j++) { A[j]=A[j+1]; } n--; } } if(flag) { cout<<"nnInvalid...Enteragain:"; goto l; } cout<<"nnnArrayformed:"; for( i=0; i<n;i++) cout<<A[i]<<""; cout<<"nnnWantto delete again: "; cin>>choice; }while(choice=='y'||choice=='Y'); }
  • 9. Output: Enter the Size of array : 5 Enter the elements: 1 3 2 4 0 Array formedis : 1 3 2 4 0 Choose fromthe following: 1. Search elementinanarray 2. Sort the array 3. Merge twoarrays 4. Insertelementinarray 5. Delete elementinarray 6. Exit Enter yourchoice : 1 1. Linearsearch 2. Binary search Enter yourchoice : 1 Enter elementtobe searched:4 SearchSuccessful. The requestedelementis4. Subscript= 3 Positioninarray= 4 Want to choose frommenuagain:Y
  • 10. Choose fromthe following: 1. Search elementinanarray 2. Sort the array 3. Merge twoarrays 4. Insertelementinarray 5. Delete elementinarray 6. Exit Enter yourchoice : 2 1. SelectionSort 2. Bubble Sort 3. Insertionsort 4. Merge Sort Enter yourchoice : 2 Array foriteration1 is: 1 2 3 4 0 Array foriteration2 is: 1 2 3 0 4 Array foriteration3 is: 1 2 0 3 4 Array foriteration4 is: 1 0 2 3 4 Array foriteration5 is: 0 1 2 3 4 Sortedarray is : 0 1 2 3 4 Want to choose frommenuagain: Y
  • 11. Choose fromthe following: 1. Search elementinanarray 2. Sort the array 3. Merge twoarrays 4. Insertelementinarray 5. Delete elementinarray 6. Exit Enter yourchoice : 2 1. SelectionSort 2. Bubble Sort 3. Insertionsort 4. Merge Sort Enter yourchoice : 4 Array aftermerge sort: 0 1 2 3 4 Want to choose frommenuagain:Y Choose fromthe following: 1. Search elementinanarray 2. Sort the array 3. Merge twoarrays 4. Insertelementinarray 5. Delete elementinarray 6. Exit Enter yourchoice : 3
  • 12. Enter yourchoice : 3 Enter size of secondarray : 5 1 0 8 9 2 Firstarray : 1 3 2 4 0 Secondarray : 1 0 8 9 2 1. Merge inascendingorder 2. Merge indescendingorder Enter yourchoice : 1 Array formedaftermerginginascendingorder: 0 0 1 1 2 2 3 4 8 9 Want to choose frommenuagain:Y 1. Seaarch elementinanarray 2. Sort the array 3. Merge twoarrays 4. Insertelementinarray 5. Delete elementinarray 6. Exit Enter yourchoice : 4 Enter elementalongwithitsposition: Element=6 Position=2 Array formed:1 6 3 2 4 0
  • 13. Want to insertagain: n Want to choose frommenuagain: y Choose fromthe following: 1. Search elementinanarray 2. Sort the array 3. Merge twoarrays 4. Insertelementinarray 5. Delete elementinarray 6. Exit Enter yourchoice : 5 Enter positionof elementto delete it:6 Invalid Enter positionof elementtodelete it:5 Array formed:1 6 3 2 Want to delete again:N Want to choose frommenuagain: y Choose fromthe following: 1. Search elementinanarray 2. Sort the array 3. Merge twoarrays 4. Insertelementinarray 5. Delete elementinarray 6. Exit Enter yourchoice : 6