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

📄 王润2004031124计算机04-1.cpp

📁 数据结构链表作业题
💻 CPP
字号:
#include  <stdio.h>
#include  <malloc.h>

typedef struct node 
{
 int data;
 struct node *next;
}Linkstack;


Linkstack *items();
Linkstack *tuils(Linkstack *q,int);
Linkstack *popls(Linkstack *q);
Linkstack *dayinls(Linkstack *q);


Linkstack *items()
{
 Linkstack *top=NULL;
 return top;
}


Linkstack *tuils(Linkstack *top,int w)
{
  Linkstack *p;
  p=(Linkstack *)malloc(sizeof(Linkstack));
  p->data=w;
  p->next=top;
  top=p;
  printf("After %d pushed into, the STACK is \n",w);
  dayinls(top);
  return p;
}


Linkstack *popls(Linkstack *top)
{
  int m;
  Linkstack *p;
  if(top==NULL)
  {
   printf("Error!");
   return NULL;
  }
  else
  {
    printf("The poped number is %d\n",top->data);
	m=top->data;
	p=top;
	top=top->next;
	free(p);
	printf("After pop %d the STACK is \n",m);
    dayinls(top);
	return top;
  }	
}


Linkstack *dayinls(Linkstack *top)
{
  Linkstack *n=top;
  while(top!=NULL)
  {
	printf("%5d\n",top->data);
	top=top->next;
  }
    return n;
}



void main()
{ 
  char a[5];
  Linkstack *top=items();
  
  for(int n=0;n<5;n++)
  scanf("%d",&a[n]);
  for(int m=0;m<5;m++)
  top=tuils(top ,a[m]);
  	
  if(top!=NULL)
  top=popls(top);
  

}

⌨️ 快捷键说明

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