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

📄 1.cpp

📁 好啊
💻 CPP
字号:
#include "stdio.h"
#include "string.h"
#include "malloc.h"
#include "iostream.h"
#include "stdlib.h"

#define NULL 0
typedef struct lnode{
int data;
lnode *next;
}lnode;
typedef struct linkQueue{
	lnode *rear;
}linkQueue;
linkQueue * clearQueue(linkQueue *q){
	lnode *p;
	p=q->rear->next;
	p->next=p;
	q->rear=p;
	return q;
}
int QueueEmpty(linkQueue *q){//非空返回0,空队列返回1
  lnode *p;
  p=q->rear->next;
  if(p->next==p)return 1;
 else return 0;
   }
linkQueue *QInsert(linkQueue *q,int x){
lnode *p,*s;
p=(lnode *)malloc(sizeof(lnode));//申请结点
p->data=x;
cout<<x<<"  ";
s=q->rear->next;
p->next=s;
q->rear->next=p;
q->rear=p;
return q;
}
linkQueue * QDelete(linkQueue *q){
	lnode *p;
	if(QueueEmpty(q)==1){
	  cout<<"this linkqueue is empty"<<endl;
	  exit(1);}
	p=q->rear->next;
	p->next=p->next->next;
	return q;
}
  void TravelLinkQueue(linkQueue *q)
  {  lnode *p,*r;//r用于遍历
  if(QueueEmpty(q)==1){
	  cout<<"this linkqueue is empty";
  }
	  p=q->rear->next;//p指向头结点
	  cout<<endl;
	  r=p->next; 
	  while(r!=p){
   cout<<r->data<<"  ";
	  r=r->next; 
	  }
	  cout<<endl;
   }
void main(){
	linkQueue *L;
    lnode *p;
	L=(linkQueue *)malloc(sizeof(linkQueue));
	p=(lnode *)malloc(sizeof(lnode));
	L->rear=p;
	p->next=p;
int x;
cout<<"请输入一个要插入的整数:";
cin>>x;
int length=0;
while(x!=0){//以0为结束符
L=QInsert(L,x);
cin>>x;
length++;
}

int i=0;
while(i<length-1){
	QDelete(L);
	i++;
}
TravelLinkQueue(L);
clearQueue(L);
TravelLinkQueue(L);
}

⌨️ 快捷键说明

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