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

📄 2.2.cpp

📁 数据结构中的一个非常好的程序~~~~~~~~~~~欢迎交流意见
💻 CPP
字号:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#define ListSize 100
#define NULL 0

struct LNode{
     int data;
     struct LNode *next;
};
struct LinkList{
     LNode *front;
     LNode *rear;};


void InitList(LinkList *L)//新建线形表L
{ 
	L->front=L->rear=NULL;
 }

int ListEmpty(LinkList *L)//验证线形表L是否为空表
{
	return L->front==NULL && L->rear==NULL;
}

void EnList(LinkList *L,int x)//初始化线形表L
{
     LNode *p;
     p=(LNode *)malloc(sizeof(LNode));//申请一个新的LNode类型的内存空间
     p->data=x;//数据为x
     p->next=NULL;
    if (ListEmpty(L))//如果线形表L为空表
		L->front=L->rear=p;//==null?
    else  //否则,若线形表不为空表
	{
		L->rear->next=p;
		L->rear=p;  
	} 
}

void DeList(LinkList *L,int *x) {
  LNode *p;
  p=L->front;     
  *x=p->data; 
  L->front=p->next;
  if (L->rear==p) 
	  L->rear=NULL;  free(p);  }


void main( ){
   LinkList  sl;  
   char ch; 
   int n;
   InitList(&sl);
   while(1)
   {
	   printf("输入命令:");  
	   scanf("%c",&ch);
        switch(ch)
		{  
           case 'a':
           case 'A':
			   printf("病历号:"); 
			   scanf("%d",&n); 
               EnList(&sl,n);
			   break;
           case 'n':
		   case 'N':
             if (ListEmpty(&sl)==0)  //如果表不为空(ListEmpty(&sl)返回值为表中无元素,即为为空)
			 {
		        DeList(&sl,&n);
	            printf("病历号为%d的病人就诊\n",n);  
			 }
             else   
				 printf("无病人等候就诊\n"); 
			     break;
            case 'q':
            case 'Q':   
				printf("排列的病人依次就诊\n");
                while (ListEmpty(&sl)==0) 
				{  DeList(&sl,&n); 
                    printf("%d\n",n); 
				}
		}
           if (ch=='x'||ch=='X')   break;  }
}

⌨️ 快捷键说明

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