Thursday, July 17, 2014

Visit a Stack

#include
using namespace std;
int main()
{
int a[5]={1,2,3,4,5},i=4;
while(i>=0){
cout<<a[i]<<endl;
i--;
}
return 0;
}

Visit a Queue

#include
using namespace std;
int main()
{
int a[5]={1,2,3,4,5},i=0;
while(a[i]!='\0' && i<5){
cout<<a[i]<<endl;
i++;
}
return 0;
}

Delete from Queue

#include
using namespace std;
int main()
{
cout<<"Delete from Quee"<<endl;
int a[5]={1,2,3,4,5},i;

for(i=0;i<=4;i++)
{
a[i]=a[i+1];
}

a[i-1]='\0';
for(i=0;i<5;i++){
cout<<a[i]<<endl;
}
return 0;
}

Insert in Queue

#‎include‬
using namespace std;
int main()
{
cout<<"Insert element in a quee: source Code"<<endl;
int a[5]={1,2,3,4},i,item=5;

for(i=0;i<5;i++)
{
if(a[i]=='\0')
{
a[i]=item;
}
}
for(i=0;i<5;i++){
cout<<a[i]<<endl;
}
return 0;
}

Delete Element from Stack

#include
using namespace std;
int main()
{
int a[8]={1,2,3,4},i=7;
while(a[i]=='\0')
{
i--;
}
a[i]='\0';

for(i=0;i<8;i++)
{
cout<<a[i]<<endl;
}
return 0;
}

Insert Element in Stack

#include
using namespace std;
int main()
{
int a[8]={1,2,3,4},item=10,i=7;
while(a[i]=='\0')
{
i--;
}
i++;
a[i]=item;

for(i=0;i<8;i++)
{
cout<<a[i]<<endl;
}
return 0;
}