解题思路:无
注意事项:无
参考代码:
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#include<string.h>
typedef struct ware_house{
int num;
struct ware_house *next;
}ware_ ,* WARE;
int push_ware(WARE head){
WARE ware1=malloc(sizeof(ware_));
ware1->next=head->next;
head->next=ware1;
scanf("%d",&ware1->num);
return 0;
}
int pop_ware(WARE head){
if(head->next==NULL)//判断栈空
return false;
WARE temp=head->next;
head->next=head->next->next;
free(temp);
return 0;
}
int read_ware(WARE head){
if(head->next==NULL){//判断栈空
printf("E\n");
}else{
printf("%d\n",head->next->num);
}
return 0;
}
int FREE(WARE head){
WARE temp=malloc(sizeof(ware_));
while(head->next!=NULL){
temp=head->next;
head->next=temp->next;
free(temp);
}
return 0;
}
int main()
{ WARE head=malloc(sizeof(ware_));
head->next=NULL;
char ch;
int n;
while(scanf("%d",&n)&&n!=0){
int count=1;
while(count<=n){
getchar();
scanf("%c",&ch);
switch(ch){
case 'P':
push_ware(head);
break;
case 'O':
pop_ware(head);
break;
case 'A':
read_ware(head);
break;
default:
break;
}
count++;
}
printf("\n");
FREE(head);
}
free(head);
return 0;
}
0.0分
1 人评分
高精度加法 (C++代码)(大数加法)浏览:948 |
C语言训练-最大数问题 (C语言代码)浏览:637 |
买不到的数目 (C++代码)浏览:878 |
【绝对值排序】 (C++代码)浏览:695 |
printf基础练习2 (C语言代码)浏览:777 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:526 |
C二级辅导-计负均正 (C语言代码)浏览:500 |
钟神赛车 (C语言代码)浏览:618 |
一元一次方程 (C语言代码)浏览:4111 |
字符串比较 (C语言代码)浏览:712 |