📄 stack.c
字号:
/* Demo of using simplest stack data sturcture, coverting numbers from Dec to Oct. * * Written by Cyril Hu (cyrilhu@gmail.com), public domain. */#include<stdio.h>#include<stdlib.h>struct a { int x; struct a *next;} *top;int stack_empty(struct a *p){ return p ? 0 : 1;}struct a *push(int i){ struct a *p; static int cnt=0; p = malloc(sizeof(struct a)); p->x = i; if(cnt++ == 0) p->next = NULL; p->next = top; top = p; return top;}struct a *pop(struct a *p){ struct a *t; t = p->next; free(p); return t;}int main(void){ int n; puts("Input a integer number"); scanf("%d", &n); while(n) { top = push(n%8); n /= 8; } while(!stack_empty(top)) { printf("%d", top->x); top = pop(top); } puts(""); return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -