Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define STACKSIZE 20
- typedef int info_t;
- typedef struct s {
- info_t S[STACKSIZE];
- int top;
- } stack;
- void Init(stack * m) {
- m->top = -1;
- }
- void StackOverflow(void) {
- fprintf(stderr, "ERROR: StackOverflow\n");
- exit(-1);
- }
- void StackUnderflow(void) {
- fprintf(stderr, "ERROR: StackUnderflow\n");
- exit(-1);
- }
- void Push(stack *m, info_t x) {
- if (m->top >= STACKSIZE - 1)
- StackOverflow();
- m->S[++(m->top)] = x;
- }
- info_t Peek(stack * m) {
- if (m->top<0)
- StackUnderflow();
- return (m->S[(m->top)]);
- }
- info_t Pop(stack *m) {
- if (m->top<0)
- StackUnderflow();
- return(m->S[(m->top)--]);
- }
- int isEmpty(stack *m) {
- return((m->top)<0);
- }
- void dek_vobin(int n,stack *m)
- {
- Init(m);
- while(n!=0)
- {
- Push(m,n%2);
- n=n/2;
- }
- while(!isEmpty(m))
- {
- printf("%d",Pop(m));
- }
- }
- int main()
- {
- stack *m;
- Init(m);
- int n;
- scanf("%d",&n);
- dek_vobin(n,m);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement