-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstacks.cpp
More file actions
93 lines (80 loc) · 1.09 KB
/
Copy pathstacks.cpp
File metadata and controls
93 lines (80 loc) · 1.09 KB
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
/*
while (int != 0)
{
if(int mod 2 == 0)
i = 1;
pushback(i);
else
{
i = 0;
pushback(i);
}
#include <stdio.h>
#include <stdlib.h>
typedef struct stack
{
int data[20];
int front;
}
*/
#include <stdio.h>
#include <iostream>
//#include <conio.h>
//#include <process.h>
#define MAX 10
using namespace std;
typedef struct stack
{
int data[MAX];
int top;
}stack;
//---------------------
int empty(stack *s)
{
if(s->top==-1)
return(1);
return(0);
}
//----------------------
int full(stack *s)
{
if(s->top==MAX-1)
return(1);
return(0);
}
//-----------------------
void push(stack *s,int x)
{
s->top=s->top+1;
s->data[s->top]=x;
}
//-----------------------
int pop(stack *s)
{
int x;
x=s->data[s->top];
s->top=s->top-1;
return(x);
}
//------------------------
int main()
{
stack s;
int num;
s.top=-1;
printf("Enter number: ");
//scanf("%d",&num);
cin >> num;
while((num!=0))
{
push(&s,num%2);
num=num/2;
}
printf("n");
while(!empty(&s))
{
num=pop(&s);
printf("%d",num);
}
return 1;
}