【数据结构_链表_List_0961】进制转换

来源:互联网 发布:哈密顿算法原理 编辑:程序博客网 时间:2024/05/22 12:21

容我说一句链表貌似把这么简单的东西复杂化了很多;


#include<stdio.h>#include<stdlib.h>typedef struct {    int data[50];    int top;}SqStack;void initstack(SqStack *&s){    s=(SqStack *)malloc(sizeof(SqStack));    s->top=-1;}int main(){    int n;    scanf("%d",&n);    SqStack *s;    initstack(s);     while(n>0)     {         s->top++;         s->data[s->top]=n%2;         n=n/2;     }     while(s->top>=0)     {         printf("%d",s->data[s->top]);         s->top--;     }    return 0;}


0 0