Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
106 lines (91 loc) · 2.02 KB

File metadata and controls

106 lines (91 loc) · 2.02 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>
#include <string.h>
using namespace std;
struct Node{
int stu_no;
char stu_name[50];
int p;
Node *next;
};
Node *top;
class stack{
public:
void push(int n,char name[],int perc);
void pop();
void display();
};
void stack :: push(int n,char name[],int perc)
{
struct Node *newNode=new Node;
//fill data part
newNode->stu_no=n;
newNode->p=perc;
strcpy(newNode->stu_name,name);
//link part
newNode->next=top;
//make newnode as top/head
top=newNode;
}
void stack ::pop()
{
if(top==NULL){
cout<<"List is empty!"<<endl;
return;
}
cout<<top->stu_name<<" is removed."<<endl;
top=top->next;
}
void stack:: display()
{
if(top==NULL){
cout<<"List is empty!"<<endl;
return;
}
struct Node *temp=top;
while(temp!=NULL){
cout<<temp->stu_no<<" ";
cout<<temp->stu_name<<" ";
cout<<temp->p<<" ";
cout<<endl;
temp=temp->next;
}
cout<<endl;
}
int main(){
stack s;
char ch;
do{
int n;
cout<<"ENTER CHOICE\n"<<"1.Push\n"<<"2.Pop\n"<<"3.Display\n";
cout<<"Make a choice: ";
cin>>n;
switch(n){
case 1:
Node n;
cout<<"Enter details of the element to be pushed : \n";
cout<<"Roll Number : ";
cin>>n.stu_no;
cout<<"Enter Name: ";
std::cin.ignore(1);
cin.getline(n.stu_name,50);
cout<<"Enter Percentage: ";
cin>>n.p;
//push data into the stack
s.push(n.stu_no,n.stu_name,n.p);
break;
case 2 :
//pop data from stack
s.pop();
break;
case 3 :
//display data
s.display();
break;
default :
cout<<"Invalid Choice\n";
}
cout<<"Do you want to continue ? : ";
cin>>ch;
}while(ch=='Y'||ch=='y');
return 0;
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.