Skip to main content

IMPLEMENTATION OF STACK USING ADT


#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int top=-1;
class mohan
{
public:
int s[10];
void push(int);
void pop();
void display();
};
void mohan::push(int n)
{
if(top>=n-1)
cout<<"\n\tSTACK IS FULL";
else
{
top++;
cout<<"\n\tEnter d element to push";
cin>>s[top];
}
}
void mohan::pop()
{
if(top==-1)
cout<<"\n\t STACK IS EMPTY";
else
{
cout<<"\n\tDeleted Element is:"<<s[top];
top--;
}

}
void mohan::display()
{
if(top==-1)
cout<<"\n\t STACK IS EMPTY";
else
{
cout<<"\n\t Elements are";
for(int i=top;i>=0;i--)
cout<<"\t"<<s[i];
}
}
void main()
{
clrscr();
int ch,n;
mohan m;
cout<<"\n\t STACK OPERATION";
cout<<"\n \t 1.push \n\t 2.pop \n\t 3.display \n\t 4.Exit";
cout<<"\n\n\t How many Element do u want";
cin>>n;
do
{
cout<<"\n\t Enter ur choice";
cin>>ch;
switch(ch)
{
case 1:
m.push(n);break;
case 2:
m.pop();break;
case 3:
m.display();break;
case 4:
exit(0); 
default:
cout<<"\n\t Choose Correct choice";
}
}while(ch!=4);
  getch();
}

Comments

Popular posts from this blog

TCP SOCKETS CHAT APPLICATION(SERVER & CLIENT) USING C

SERVER #include<stdio.h> #include<netinet/in.h> #include<sys/types.h> #include<sys/socket.h> #include<netdb.h> #include<stdlib.h> #include<string.h> #define MAX 80 #define PORT 43454 #define SA struct sockaddr void func(int sockfd) { char buff[MAX]; int n; for(;;) { bzero(buff,MAX); read(sockfd,buff,sizeof(buff)); printf("From client: %s\t To client : ",buff); bzero(buff,MAX); n=0; while((buff[n++]=getchar())!='\n'); write(sockfd,buff,sizeof(buff)); if(strncmp("exit",buff,4)==0) { printf("Server Exit...\n"); break; } } } int main() { int sockfd,connfd,len; struct sockaddr_in servaddr,cli; sockfd=socket(AF_INET,SOCK_STREAM,0); if(sockfd==-1) { printf("socket creation failed...\n"); exit(0); } else printf("Socket successfully created..\n"); bzero(&servaddr,sizeof(servaddr)); servaddr.sin_family=AF_...

SIMULATION OF SLIDING WINDOW PROTOCOLS USING C

SENDER #include<sys/socket.h> #include<sys/types.h> #include<netinet/in.h> #include<netdb.h> #include<stdio.h> #include<string.h> #include<stdlib.h> #include<unistd.h> #include<errno.h> int main() { int sock,bytes_received,connected,true=1,i=1,s,f=0,sin_size; char send_data[1024],data[1024],c,fr[30]=" "; struct sockaddr_in server_addr,client_addr; if((sock=socket(AF_INET,SOCK_STREAM,0))==-1) { perror("Socket not created"); exit(1); } if(setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(int))==-1) { perror("Setsockopt"); exit(1); } server_addr.sin_family=AF_INET; server_addr.sin_port=htons(17000); server_addr.sin_addr.s_addr=INADDR_ANY; if(bind(sock,(struct sockaddr *)&server_addr,sizeof(struct sockaddr))==-1) { perror("Unable to bind"); exit(1); } if(listen(sock,5)==-1) { perror("Listen"); exit(1); } fflush(stdout); sin_size=sizeof(st...

UDP SOCKETS CHAT APPLICATION (SERVER & CLIENT) USING C

SERVER #include<stdio.h> #include<netinet/in.h> #include<sys/types.h> #include<sys/socket.h> #include<netdb.h> #include<string.h> #include<stdlib.h> #define MAX 80 #define PORT 43454 #define SA struct sockaddr void func(int sockfd) { char buff[MAX]; int n,clen; struct sockaddr_in cli; clen=sizeof(cli); for(;;) { bzero(buff,MAX); recvfrom(sockfd,buff,sizeof(buff),0,(SA *)&cli,&clen); printf("From client %s To client",buff); bzero(buff,MAX); n=0; while((buff[n++]=getchar())!='\n'); sendto(sockfd,buff,sizeof(buff),0,(SA *)&cli,clen); if(strncmp("exit",buff,4)==0) { printf("Server Exit...\n"); break; } } } int main() { int sockfd; struct sockaddr_in servaddr; sockfd=socket(AF_INET,SOCK_DGRAM,0); if(sockfd==-1) { printf("socket creation failed...\n"); exit(0); } else printf("Socket successfully created..\n"); bzero(&servaddr,sizeof(s...