新建 文本文档 (2).txt

来自「用链表结构完成堆栈的任务」· 文本 代码 · 共 51 行

TXT
51
字号
#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 + =
减小字号Ctrl + -
显示快捷键?