标题:数据结构
取消只看楼主
好聚好散
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:138
专家分:123
注 册:2012-12-4
结帖率:77.42%
已结贴  问题点数:20 回复次数:3 
数据结构
#include<stdio.h>
#include<stdlib.h>

typedef struct SNode
{
    char data;
    struct SNode* next;
}SNode, *LinkStack;
int InitStack(LinkStack *top)
{
    *top = (LinkStack)malloc(sizeof(SNode));
    if (*top == NULL)
    {
        printf("chu sh hua");
        return 0;
    }
    (*top)->next = NULL;
    return 1;
}
int StackEmpty(LinkStack top)
{
    if (top->next == NULL)
    {
        return 1;
    }
    return 0;
}
int Pop(LinkStack top, char *e)
{
    SNode *p;

    p = top -> next;
    top->next = p->next;
    *e = p -> data;
    free(p);
    return 1;
}
int Push(LinkStack top, char e)
{
    SNode *p;
    p = (SNode *)malloc(sizeof(SNode));
    if (!p)
    {
        printf("chu cyo ");
        return 0;
    }
    p->data = e;
    p->next = top->next;
    top->next = p;
    return 1;
}
void Convert(int num, int d)
{
    LinkStack s;
    char ch[] = "0123456789ABCDEF";
    char tmp;
    InitStack(&s);

    do
    {
        Push(s, ch[num%d]);
        num = num/d;
    }while(num!=0);
    while(!StackEmpty(s))
    {
        Pop(s, &tmp);
        printf("%c", tmp);
    }
}
int main(void)
{
    int num, d;

    printf("input num, d\n");
    scanf("%d%d", &num, &d);
    Convert(num, d);
    printf("\n");
    return 1;
}
看看我的水平吧
搜索更多相关主题的帖子: next include return 
2013-04-07 09:56
好聚好散
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:138
专家分:123
注 册:2012-12-4
得分:0 
真心不知道学写代码能干嘛,,有点迷茫,,求指点迷津

无节操,无真相
2013-04-08 09:08
好聚好散
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:138
专家分:123
注 册:2012-12-4
得分:0 

无节操,无真相
2013-04-09 11:34
好聚好散
Rank: 3Rank: 3
等 级:论坛游侠
威 望:1
帖 子:138
专家分:123
注 册:2012-12-4
得分:0 
回复 8楼 nuistkevin
wo去年买了个表,,歧视非211

无节操,无真相
2013-04-18 19:09



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-403190-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.296911 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved