Вы находитесь на странице: 1из 7

#include<iostream.

h>
#include<conio.h>
#include<stdio.h>
struct Student
{
int rno;
char name[20];
int std;
}temp,S[10];
int top=-1;
void push()
{
if(top==0)
cout<<"Overflow!\n\n";
else
{
cout<<"Enter the roll number=";
cin>>temp.rno;
cout<<"Enter the student's name=";
gets(temp.name);
cout<<"Enter the class=";
cin>>temp.std;
cout<<endl;
if(top==-1)
top=0;
else
top++;
S[top]=temp;
}
}
void pop()
{
if(top==-1)
cout<<"Underflow!\n\n";
else
{
cout<<"Popping\n";
cout<<"Roll number"<<S[top].rno;
cout<<"\nName:";
puts(S[top].name);
cout<<"Class:"<<S[top].std<<endl;
top--;
}
}
void display()
{
if(top==-1)
cout<<"Stack is empty\n";
else
{
cout<<"Stack contents:-\n";
for(int i=top;i>=0;i--)
{
cout<<"Roll number:"<<S[i].rno;
cout<<"\n Name:";
puts(S[i].name);
cout<<"Class:"<<S[i].std<<endl;
}
}
}
void main()
{
clrscr();
int ch;
again:cout<<"1.Push record\n2.Pop record\n3.Display records\n4.Exit";
cout<<"\nEnter a choice(1/2/3/4)=";
cin>>ch;
switch(ch)
{
case 1:cout<<"Pushing record\n";
push();
goto again;
case 2:cout<<"Popping record\n";
pop();
goto again;
case 3:cout<<"Displaying records\n";
display();
goto again;
case 4:break;
default:cout<<"Invalid choice.Please try again\n";
goto again;
}
}
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
struct Student
{
int rno,std;
char name[20];
Student *next;
}*temp;
Student*top=NULL;
void push()
{
Student*S=new Student;
if(S==NULL)
cout<<"Error! Cannot create node!\n";
else
{
cout<<"Enter the roll number=";
cin>>S->rno;
cout<<"Enter the name of the student=";
gets(S->name);
cout<<"Enter the class=";
cin>>S->std;
cout<<"\n";
S->next=NULL;
if(top==NULL)
top=S;
else
{
temp=top;
top=S;
S->next=temp;
}
}
}
void pop()
{
if(top==NULL)
cout<<"Underflow!\n";
else
{
cout<<"Popping:-\n";
cout<<"Roll number="<<top->rno<<endl;
cout<<"Name=";
puts(top->name);
cout<<"Class="<<top->std<<endl;
temp=top;
top=top->next;
delete(temp);
}
}
void display()
{
Student*ptr=top;
if(ptr==NULL)
cout<<"Stack is empty\n";
else
{
cout<<"Stack contents\n";
while(ptr!=NULL)
{
cout<<"Roll number="<<ptr->rno<<endl;
cout<<"Name=";
puts(ptr->name);
cout<<"Class="<<ptr->std<<endl;
ptr=ptr->next;
}
}
}
void main()
{
clrscr();
int ch;
again:cout<<"1.Push record\n2.Pop record\n3.Display records\n4.Exit";
cout<<"\nEnter a choice(1/2/3/4)=";
cin>>ch;
switch(ch)
{
case 1:cout<<Pushing the record\n";
push();
goto again;
case 2:cout<<"Popping record\n";
pop();
goto again;
case 3:cout<<"Displaying records\n";
display();
goto again:
case 4:break;
default:cout<<"Invalid choice.Please try again\n";
goto again;
}
}
//queue as an array
#include<iostream.h>
#include<conio.h.>
#include<stdio.h>
const int size=5;
class employee
{
int empno;
char name[30];
long salary;
public:
void getdata()
{
cout<<"\nenter the employee number: ";
cin>>empno;
cout<<"\nenter the name: ";
gets(name);
cout<<"\nenter salary: ";
cin>>salary;
}
void putdata()
{
cout<<"Details:"<<"\nemployee number: "<<empno;
cout<<"\nname: ";
puts(name);
cout<<"\nsalary: "<<salary;
}
}s[5];
int front=-1,rear=-1;
void insert()
{
employee temp;
temp.getdata();
if(rear=size-1)
{return;}
if(rear==-1)
{
front=rear=0;
s[front]=temp;
}
else
{
rear=rear+1;
s[rear]=temp;
}
}
void del()
{
if(front==-1)
{
cout<<"\nunderflow";
return;
}
else if(front==rear)
{
cout<<"\ndeleting";
s[front].putdata();
front=rear=-1;
}
else{
cout<<"\ndeleting";
s[front].putdata();
front=front+1;
}
}
void disp()
{
if(rear==-1)
{
cout<<"error";
return;
}
else{
cout<<"\nqueue: \n";
for(int i=front;i<=rear;;i++)
{
s[i].putdata();
}
}
}
void main()
{
clrscr();
char ch;
int opt;
do
{
cout<<"\n1.insert\n2.delete\n3.display: ";
cout<<"enter option";
cin>>opt;
switch(opt)
{
case 1:
insert();
break;
case 2:
del();
break;
case 3:
disp();
break;
cout<<"do you want to continue? ";
cin>>ch;
}
while(ch=='y'||ch=='Y')
getch();
}
}

Вам также может понравиться