?? linktostack.txt
字號:
#include "stdio.h"
#include "stdlib.h"
typedef struct node
{//鏈表結構
char data;
struct node *next;
}stnode;
void init(stnode *stacklink)
{//初始化鏈表
stacklink->next=NULL;
}
void push(stnode *stacklink)
{//進行進鏈表操作
char ch;
stnode *mode;
mode=(stnode *)malloc(sizeof(stnode));
printf("please input one char:");
ch=getch();
printf("%c",ch);
printf("\n");
if(ch!='\n')
{ mode->data=ch;
mode->next=NULL;
if(stacklink->next==NULL)
{ stacklink->next=mode;
}
else
{ mode->next=stacklink->next;
stacklink->next=mode;
} } }
void pop(stnode *stacklink)
{//出鏈表操作
stnode *dele;
dele=(stnode *)malloc(sizeof(stnode));
dele=stacklink->next;
if(dele!=NULL)
{
stacklink->next=dele->next;
dele->next=NULL;
printf("output stack char:%c\n",dele->data);
}
else
printf("the stack is empty.\n");
free(dele);
}
void linktostack()
{//用鏈表模擬棧的操作函數
char ch;
stnode *stacklink;
stacklink=(stnode *) malloc(sizeof(stnode));
init(stacklink);
printf("\t1.push\t2.pop\t0.exit\n");
printf("please input your opretor:");
scanf("%c",&ch);
printf("\n");
while(1)
{
if(ch=='1')
{
printf("push\n");
push(stacklink);
}
else if(ch=='2')
{
printf("pop\n");
pop(stacklink);
}
else
exit(0);
printf("-----------------------------
--------\n"); main()
printf("\t1.push\t2.pop\t0.exit\n"); {
printf("please input your opertor:"); clrscr();
ch=getch(); printf("the star:\n");
printf("%c",ch); linktostack();
printf("\n"); return 0;
} }
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -