jmu数据结构软2 master·ye小组实验讨论

DSleaf 2021-04-22 08:46:40
数据结构课程要求在论坛进行小组讨论,这是master·ye小组实验讨论贴
...全文
1893 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
源代码大师 2021-04-26
  • 打赏
  • 举报
回复
C和C++ 完整教程:https://blog.csdn.net/it_xiangqiang/category_10581430.html C和C++ 算法完整教程:https://blog.csdn.net/it_xiangqiang/category_10768339.html
柚柚草莓橘子 2021-04-23
  • 打赏
  • 举报
回复
c语言直接暴力比较字符串是否对称。 bool palindrome(char *s) { int len; len = strlen(s); for (int i = 0; i < len; i++) { if (*(s + i) != *(s+len - i - 1)) return false; } return true; } 使用队列比较 bool palindrome(char *s){ stack<char> s; queue<char> q; int i=0; while(*s++ !='\n') { s.push(*s); q.push(*s); i++; } while(i--) { if(s.top()==q.front()){ s.pop(); q.pop(); } else return false; } return ture; } 通过入栈两个队列,以不同的出队方式实现比较。
lgphhh 2021-04-23
  • 打赏
  • 举报
回复
#include<queue>
#include<stdio.h>
using namespace std;
int main(){
	queue<int>s; 
	int h,i; 
	for(h=0;h<10;h++){
	scanf("%d",&i);
	s.push(i);
}
for(h=0;h<5;h++){
	printf("%d",s.front());
	s.pop();
}
printf("%d %d %d",s.front(),s.back(),s.size());
h=0;
	while (!s.empty())
	{
		printf("%d",s.front());
		s.pop();
		h++;
	}
	printf("%d",h);
	return 0;
} 
叶酱教我的实验一。
⑥66 2021-04-23
  • 打赏
  • 举报
回复
叶酱真棒!!!
尘埃Х° 2021-04-22
  • 打赏
  • 举报
回复
bool Ispalindrome(SqStack *&s){
    SqStack *q;
    InitStack(q);
    int i=0;
    char e;
    while(StackEmpty(s)){
        GetTop(s,e);
        Pop(s,e);
        Push(q,e);
    }
    for(i=0;i<=MaxSize;i++){
        if(q->data[i]!=s->data[i])
            break;
    }
    if(i!=MaxSize)
        return true;
    else
        return false;
}
InitStack(q):为函数的初始化 GetTop(s,e)取栈顶的元素,并赋值给e 根据的栈的“后进先出“原则,进行退栈操作,并将退栈元素进栈q,后比较q与s即可
lgphhh 2021-04-22
  • 打赏
  • 举报
回复
叶酱真帅!!!!!!!!!!!!
DSleaf 2021-04-22
  • 打赏
  • 举报
回复
直接比较首尾是否相等

bool palindrome( char *s )
{
	int n,i;
	n=strlen(s)-1;
	for(i=0;i<=n/2;i++)
	  if(s[i]!=s[n-i])
	    return false;
	return true; 
}
用数组模拟栈,前一半字符进栈保存,在一个个出栈与后半字符进行比较

bool palindrome(char* s)
{
    int mid, top = -1, i = 0;
    char xn[200] = { 0 };
    mid = strlen(s) / 2;
    while (i != mid)
    {
        top++;
        xn[top] = s[i];
        i++;
    }
    if (strlen(s) % 2 == 1 && strlen(s) != 1)
        i++;
    while (i != strlen(s) - 1)
    {
        if (xn[top] != s[i])
            return false;
        else
        {
            top--;
            i++;
        }
    }
    return true;
}
DSleaf 2021-04-22
  • 打赏
  • 举报
回复
第一个实验:PTA:字符串是否对称

15,440

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧