-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPractical4-1.c
91 lines (83 loc) · 1.16 KB
/
Practical4-1.c
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
#include <stdio.h>
#include <stdlib.h>
void push();
void pop();
int peek();
void display();
typedef struct node
{
int a;
struct node *nxt;
}node;
node *top;
void create()
{
top=NULL;
}
int main ()
{ int num,temp,temp2;
int reverse=0;
node *node;
printf("Enter the Number\n");
scanf("%d",&num);
temp = num;
create();
while(temp){
temp2=temp%10;
push(temp2);
temp/=10;
}
display(node);
temp=num;
while(temp)
{
temp2=temp%10;
push(temp2);
reverse=(reverse*10)+peek();
pop();
temp=temp/10;
printf("\nReverse Operation :%d\n",reverse);
}
return 0;
}
void push (int x)
{
node *temp;
temp=malloc(sizeof(node));
temp->a=x;
temp->nxt=top;
top=temp;
}
void pop()
{
node *temp1;
temp1=top;
top=top->nxt;
free(temp1);
}
int isEmpty()
{
return top==NULL;
}
int peek(){
if(!isEmpty())
{
return top->a;
}
else
{
printf("\nStack Underflow");
}
}
void display(node *disp)
{
int z;
disp=top;
printf("\nElements In stack are : ");
while(disp!=NULL)
{
z=disp->a;
printf(" %d ",z);
disp=disp->nxt;
}
}