⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 24.c

📁 用链表结构完成堆栈的任务
💻 C
字号:
#include<stdio.h>
#define null 0

typedef struct node  /*定义结构体*/
{
int data;
struct node * next;
}slnode;


void initiatels(slnode *h)
{
h=(slnode*)malloc(sizeof(slnode));
h->next=null;
}

void pushls(slnode *h,int x)
{
slnode *p;
p=(slnode*)malloc(sizeof(slnode));
p->data=x;
p->next=h->next;
h->next=p;
}

main()
{
int ch;
slnode *h,*p;
initiatels(h);
printf(">");
scanf("%d",&ch);
while(ch!=-1)
{
pushls(h,ch);
scanf("%d",&ch);
}
p=h->next;


while(p->next!=null)
{
p=h->next;
h->next=p->next;
ch=p->data;
printf("%d",ch);
}

printf("\n");
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -