·
一、队列
解密QQ号
小哈给小哼一串加密后的数字,并告知解密规则:首先将第一个数删除,紧接着将第二个数放到这串数的末尾,再将第三个数删除并将第四个数放到这串数的末尾,再将第五个数删除……直到剩下最后一个数,将最后一个数也删除。按照刚才删除的顺序,把这些删除的数连在一起就是小哈的QQ号。
#include<stdio.h>
#include<stdlib.h>
int main()
{
int q[100], n, i, head, tail;
printf("Please enter the number of the numbers : "); //接下来将输入n个数
scanf_s("%d", &n);
printf("Please enter the number you want : ");
for (i = 0; i < n; i++) //循环读入n个数到队列
{
scanf_s("%d", &q[i]);
}
head = 0; //队首
tail = n ; //队尾的下一个位置(避免队首队尾重合)
while (head < tail) //当队列不为空的时候执行循环
{
//打印队首并将队首出队
printf("%d ", q[head]);
head++;
//将新队首的数添加到队尾
q[tail] = q[head];
tail++;
//再将队首出队
head++;
}
system("pause");
return 0;
}
运行结果:
Please enter the number of the numbers : 9
Please enter the number you want : 6 3 1 7 5 8 9 2 4
6 1 5 9 4 7 2 8 3 请按任意键继续. . .
队列是先进先出,首部出队,尾部入队。
·
·
·
二、栈
判断字符串是否为回文
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[101], s[101];
int i, len, mid, next, top;
printf("Please enter the