zoukankan      html  css  js  c++  java
  • 链式队列

    #include "stdafx.h"
    
    #include <iostream>
    using namespace std;
    
    typedef int DataType1;
    
    typedef struct qnode{
    	DataType1 data;
    	struct qnode *next;//在结构体中调用结构体本身,要用qnode,也就是括号前的名字
    }QNode,*linkQ;
    
    typedef struct
    {
    	linkQ front;//头节点
    	linkQ rear;//尾节点
    }LinkQueue;
    
    void initLQ(LinkQueue *Q)
    {
    	//初始化头节点
    	Q->front = (linkQ)malloc(sizeof(QNode));
    	if(!Q->front) exit(0);
    	Q->rear = Q->front;
    	Q->front->next = NULL;
    }
    
    void inQueue1(LinkQueue *Q,DataType1 e)
    {
    	linkQ p;
    	p = (linkQ)malloc(sizeof(QNode));
    	if(!p) exit(0);
    	p->data = e;
    	p->next = NULL;
    	Q->rear->next = p;
    	Q->rear = p;
    }
    void outQueue1(LinkQueue *Q)
    {
    	linkQ p;
    	if(Q->front == Q->rear) 
    	{
    		cout<<"queue is empty"<<endl;
    		exit(0);
    	}
    	p=Q->front->next;
    	cout<<"out:"<<p->data<<endl;
    	Q->front->next = p->next;
    	if(Q->rear == p) Q->rear = Q->front;
    	free(p);
    
    }
    
    /*void main()
    {
    	LinkQueue Q ;
    	initLQ(&Q);
    	inQueue1(&Q,1);
    	inQueue1(&Q,2);
    	outQueue1(&Q);
    	outQueue1(&Q);
    
    }*/
    

      

  • 相关阅读:
    2010浙大:zoj问题
    Meta 数据中文显示
    django 中间件
    url的配置
    django.contirb
    os模块
    线程和异步
    ADO.NET
    C#托管代码 CLR
    C#垃圾回收
  • 原文地址:https://www.cnblogs.com/waiwai4701/p/4207942.html
Copyright © 2011-2022 走看看