= '\0') && (*source == *dest)) { source++; dest++; } return ( (*source) - (*dest) ) -1 : 0; } 157 写一函数 int fun(char *p)判断一字符串是否为回文,是返回 1,不是返回 0,出错返回 -1 答案:一、 int fun(char *p) { if(p==NULL) return -1; else { int length = 0;...
例如,在C++中,对函数void fun(int,int)编译后的名称可能是_fun_int_int,而C中没有重载机制,一般直接利用函数名来指定编译后函数的名称,如上面的函数编译后的名称可能是_fun。这样问题就来了,如果在C++中调用的函数如上例中的fun(1,2)是用C语言在源文件a_module.c中实现和编译的,那么函数fun在目标文件a_...
mt Palindiome_Test()//判别输入的字符串是否回文序列,是则返回 1,否则返回 0 {InitStack(S);IiiitQueue(Q); while((c=getchar())!') { Push(S,c);EnQueue(Q,c); //同时使用栈和队列两种结构 } while(! StackEmpty(S)) { Pop(S,a);DeQueue(Q,b)); if(a!=b) leturn ERROR; } return...
实验要求: 回文判断:对于一个从键盘输入的字符串,判断其是否为回文。回文即正反序相同。如“abba”是回文,而“abab”不是回文。 实验主要步骤 (1)数据从键盘读入; (2)输出要判断的字符串; (3)利用栈的基本操作对给定的字符串判断其是否是回文,若是则输出“Yes”,否则输出“No”。
()//判别输入的字符串是否回文序列 ,是则返回 1, 否则返回 0 { InitStack(S);InitQueue(Q); while((c=getchar()!='@') { Push(S,c);EnQueue(Q,c); //同时使用栈和队列两种结构 } while(!StackEmpty(S)) { Pop(S,a);DeQueue(Q,b)); if(a!=b) return ERROR; } return OK; }//...
(1) status algo1(Stack S) { int i,n,A[255]; n=0; while(!StackEmpty(S)) { n++; Pop(S,A[n]); } for(i=1;i<=n;i++) Push(S,A[i]); } (2) status algo2(Stack S,int e) { Stack T; int d; InitStack(T); while(!StackEmpty(S)){ Pop(S,d); if(d!=e) ...
bool Stack_Empty() { if (this.size == -1) { return true; } else return false; } int Stack_Full() { if (this.size == max_size) { return true; } else return false; } DataType GetTop() { if (!Stack_Empty()) { return data[size]; ...
(3)void proc_3(Queue *Q) { Stack S; int d; InitStack(&S); while(!EmptyQueue(*Q)) { DeleteQueue(Q, &d); Push( &S, d); } while(!EmptyStack(S)) { Pop(&S, &d); 16 / 89 EnterQueue(Q,d) } } 将队列 Q 逆序。 实习题 1. 回文判断。称正读与反读都相同的字符序列为“...
1 p=h->next2 p=p->next; 3 请编写函数 fun,函数的功能是:判断字符串是否为回文?是,函数返回 1,主函数中输 出: YES, 否则返回 0, 主函数中输出 NO。 回文是指顺读 t 和倒读都一样的字符串。 123312 int i,n=0,flag=1; char *p=str; while (*p) { n++; p++; } for(i=0;i<n/2;...
4、(本题5分)用户输入一个字符串,程序判断其是否为回文串的同时忽略其中的空格和标点符号。5、(本题5分)设计一个程序,用户输入一个正整数n,生成一个n行的空心菱形图案(由数字组成)。四、分析题(本大题共3个小题,共30分)1、(本题10分)分析Java中反射机制在框架开发中的应用。2、(本题10分)简述C语言...