标题:[求助]栈的问题
只看楼主
水木子
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2006-10-5
 问题点数:0 回复次数:1 
[求助]栈的问题

# include <stdio.h>
# include <stdlib.h>
# include <malloc.h>
# define Init_size 100
# define New_size 10

typedef struct {
int *base ,* top ;
int size;
} SqStack;

int InitStack (SqStack *S)
{
S->base=(int* )malloc (Init_size *sizeof(int) );
if (!S->base)
return (1);
else {
S->top =S->base;
S->size=Init_size;
return (0);
}

}
int Push (SqStack *S,int ch){
if (S->top-S->base>=S->size) {
S->base=(int *)realloc (S->base, (S->size+New_size)*sizeof (int));
if (!S->base)
{
return (1);
}
S->top=S->base+S->size;
S->size +=New_size;
}
*S->top=ch;
S->top++;
}

int Pop (SqStack *S)
{
if (S->top!=S->base)
return (*(--S->top));
}

void ClearStack (SqStack *S) {
if (S->top!=S->base)
S->top=S->base;

}

main (){

SqStack s;
int num,jz,a,result;
if (InitStack (&s))
{
puts ("fail!!\n");
exit (0);
}
ClearStack (&s);
puts ("please input a operation num\n");

scanf ("%d",&num);
if (num<0)
result=-num;
printf ("please input which JIN Zhi do you want \n");
scanf ("%d",&jz);

while (result)
{ a=result%jz ;
Push (&s,a);
result=result/jz;
}

if (num<0)
printf ("-");
while (s.top!=s.base){
printf ("%d",Pop(&s));
}
printf ("\n");
}

无论我输入什么结果都是一样的
怎么会这样
是算法错了吗

2006-10-15 16:00
卧龙孔明
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:59
帖 子:3872
专家分:684
注 册:2006-10-13
得分:0 

请写明要求助的问题


My Blog: www.aiexp.info
虽然我的路是从这里开始的,但是这里不再是乐土.感谢曾经影响过,引导过,帮助过我的董凯,飞燕,leeco,starwing,Rockcarry,soft_wind等等等等.别了,BCCN.
2006-10-15 16:51



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




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

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