Showing posts with label Data Structure Programs. Show all posts
Showing posts with label Data Structure Programs. Show all posts

Wednesday, August 28, 2013

C++ Program to push an item in a stack

#include<iostream>
using namespace std;
int main(){
int stack[10],top=-1,n,i;
if(top==9)
cout<<"Stack is Full";
else{
cout<<"Enter the item to be inserted:";
cin>>n;
top=top+1;
stack[top]=n;
}
cout<<"You have inserted:";
cout<<stack[top];
return 0;
}

Output:-




Tuesday, August 27, 2013

C++ Program for iterative linear search

#include<iostream>
using namespace std;
int main(){
int a[40],it,p=0,i,n;
cout<<"Enter the number of elements";
cin>>n;
for(i=0;i<n;i++){
cin>>a[i];
}
cout<<"Enter item to be searched";
cin>>it;
for(i=0;i<n;i++){
if(a[i]==it){
p=i+1;
break;
}
}
if(p>0){
cout<<"item found at "<<p<<" position";
}
else
cout<<"Item not found";

return 0;
}

Output:-


Download the program  :- Pdf and source file(.cpp)

Ads Inside Post