Код: Выделить всё
#include <iostream>
using namespace std;
typedef struct stack{
char data;
struct stack *next;
}Item;
Item *top;
void Push(void);
void Pop(void);
void Display(void);
void razmer(void);
static int n;
int main(){
razmer();
top=0;
int done=false;
char c;
while(!done){
Display();
printf("\n\nA)dd,D)elete,Q)uit \n");
c=getchar();
switch(toupper(c)){
case 'A':
Push();
break;
case 'D':
Pop();
break;
case 'Q':
done=true;
break;
}
}
return 0;
}
void Push(){
Item *p;
for(;n;n--){
p=(Item *)malloc(sizeof(Item));
printf("Your symbol; ");
scanf("%c",&p->data);
p->next=top;
top=p;
}
}
void Pop(){
Item *p;
if(top!=NULL){
p=top;
top=top->next;
free(p);
}
}
void Display(){
Item *p=top;
if(p==NULL)
printf("\nstack is empty \n");
else
printf("\n\nStack;\n");
while(p!=NULL){
printf("\n%c",p->data);
p=p->next;
}
}
void razmer(){
printf("ramer\n");
scanf("%i",&n);
}