解题思路:无
注意事项:无
参考代码:
#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语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:562 |
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:468 |
C语言训练-排序问题<1> (C语言代码)浏览:621 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:563 |
C语言程序设计教程(第三版)课后习题7.5 (C语言代码)浏览:541 |
C语言程序设计教程(第三版)课后习题7.2 (C语言代码)浏览:666 |
C语言程序设计教程(第三版)课后习题8.7 (C语言代码)浏览:602 |
C语言训练-数字母 (C语言代码)浏览:629 |
陈教主的三角形 (C语言代码)浏览:1167 |
陶陶摘苹果2 (C语言代码)浏览:608 |