数据结构第三章习题答案

判断回文palindrome:

#include <iostream>

#include <string>

using namespace std;

bool huiwen(string s)

{

int n=s.length();

int i,j;

i= 0;

j=n-1;

while(i<j && s[i]==s[j]){ i++;j--;}

if(i>=j) return true;else return false;

}

int main()

{

string s1;

cin>>s1;

cout<<huiwen(s1);

return 0;

}

=============

(2)设从键盘输入一整数的序列:a1, a2, a3,…,an,试编写算法实现:用栈结构存储输入的整数,当ai≠-1时,将ai进栈;当ai=-1时,输出栈顶整数并出栈。算法应对异常情况(入栈满等)给出相应的信息。

#include <iostream>

using namespace std;

#define OVERFLOW -2

#define OK 1

#define ERROR 0

typedef int SElemType;

typedef int Status;

typedef struct {

SElemType a[5];

int top;

} SqStack;

Status InitStack(SqStack &S){

S.top=0;

return OK;

}

Status Push(SqStack &S,SElemType e){

你可能喜欢

  • 数据结构第三版答案
  • 自考社会学概论复习资料
  • 数据结构习题
  • 社会学概论重点
  • 离散数学期末考试

数据结构第三章习题答案相关文档

最新文档

返回顶部