| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1128 人关注过本帖
标题:我写的回文函数有问题吗
只看楼主 加入收藏
diaoxue
Rank: 1
等 级:新手上路
帖 子:142
专家分:0
注 册:2007-6-1
收藏
 问题点数:0 回复次数:3 
我写的回文函数有问题吗

帮忙看下我写的回文函数Huiwen和主函数
我输入什么字符串怎么输入都是1啊

#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <iostream.h>
#include <string.h>

#define STACK_INIT_SIZE 100
#define STACKINCREMENT 10
#define MAX 100

typedef struct
{
int *base;
int *top;
int stacksize;
}SqStack;

void InitStack(SqStack &S)
{
S.base=(int *)malloc(STACK_INIT_SIZE *sizeof(int));
if(!S.base)exit(1);
S.top=S.base;
S.stacksize=STACK_INIT_SIZE;
}

/*int GetTop(SqStack &S,int &e)
{
if(S.top==S.base)return 0;
e=*(S.top-1);
return e;
}*/

void Push(SqStack &S,char e)
{
if(S.top-S.base>=S.stacksize)
{
S.base=(int *)realloc(S.base,(S.stacksize+STACKINCREMENT)*sizeof(int));
if(!S.base)exit(1);
S.top=S.base+S.stacksize;
S.stacksize+=STACKINCREMENT;
}
*S.top=e;
S.top++;
}

char Pop(SqStack &S,char &e)
{
if(S.top==S.base)exit(1);
e=*S.top;
--S.top;
return e;
}
bool StackEmpty(SqStack &S)
{
if(S.base==S.top)return true;
return false;
}

/*void Conversion()
{
int N,e;
SqStack S;
InitStack(S);
printf("input the number which you want to conver:");
scanf("%d",&N);
while(N)
{
Push(S,N%2);
N=N/2;
}
while(!StackEmpty(S))
{
Pop(S,e);
printf("%d",e);
}
}*/

int Strequl(char str[],char str1[])
{
int i,j;
int length0=strlen(str);
int length1=strlen(str1);
if(length0 != length1)return 0;
for(i=0,j=0;i<length0 && j<length1;i++,j++)
{
if(str[i]!=str1[j])
break;
}
if(i!=length0 || j!=length1)return 0;
return 1;
}

int Huiwen()
{
char str[MAX],str1[MAX];
SqStack S;
InitStack(S);
printf("input your string:");
gets(str);
int length=strlen(str);
int j=0;
// char str1[length];
for(int i=1;i<=length;i++)
Push(S,str[i]);
while(!StackEmpty(S))
{
Pop(S,str[j]);
j++;
}
cout<<strcmp(str,str1);
// cout<<Strequl(str,str1);
return 0;
}

int main()
{
// Conversion();
Huiwen();
return 0;
}

搜索更多相关主题的帖子: 回文函数 int include base STACK 
2007-11-18 11:15
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 
我就是知道太烦琐了.程序长了.

倚天照海花无数,流水高山心自知。
2007-11-18 11:27
succubus
Rank: 9Rank: 9Rank: 9
等 级:蜘蛛侠
威 望:4
帖 子:635
专家分:1080
注 册:2007-10-7
收藏
得分:0 
以下是引用nuciewth在2007-11-18 11:27:30的发言:
我就是知道太烦琐了.程序长了.

呵呵
和我一样
不过楼主估计是要练习栈的用法
那么这么写也就没什么了
ps:程序太长,实在不想看了,楼主自己设个断点,单步调试一下吧
要学会自己进行调试啊。


[url=http:///view/aDU1]/image/aDU1.gif" border="0" />[/url]
2007-11-18 11:30
diaoxue
Rank: 1
等 级:新手上路
帖 子:142
专家分:0
注 册:2007-6-1
收藏
得分:0 

栈的实现应该是对的
我也是用栈实现的进制转换了
就是写了回文函数,就出现问题了
我想就是那儿出问题了
遇到编译器提示出错的我还能对付
编译没错就不知道怎么办了、
断点不像matlab那样容易 那是一句一句没什么关系的


上善若水,水善利万物而不争,处众人之所恶
2007-11-18 12:59
快速回复:我写的回文函数有问题吗
数据加载中...
 
   



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

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