zoukankan      html  css  js  c++  java
  • 线性队列

    #include "stdafx.h"
    
    #include <iostream>
    using namespace std;
    
    typedef int DataType;
    #define SIZE 100
    
    typedef struct {
    	DataType data[SIZE];
    	int head,tail;
    }SqQueue;
    
    //初始化
    SqQueue init(SqQueue *Q)//顺序型数据结构,初始化之类的方法一定要有返回值
    {
    	Q = (SqQueue*)malloc(sizeof(SqQueue));
    	if(Q==NULL) 
    	{
    		printf("%s","init failed");
    		exit(0);
    	}
    	else
    	{
    		Q->data[0]=0;
    		Q->head = 0;
    		Q->tail = 0;
    	}
    	return *Q;
    }
    //判断是否为空
    int isQempty(SqQueue *Q)
    {
    	if(Q->head == Q->tail) return 1;
    	else return 0;
    }
    //判断是否满
    int isQfull(SqQueue *Q)
    {
    	if(Q->tail == SIZE) return 1;
    	else return 0;
    }
    //进
    void inQueue(SqQueue *Q,DataType e)
    {
    	if(isQfull(Q) ==1) 
    	{
    		cout<<"full"<<endl;
    			exit(0);
    	}else
    	{
    		cout<<"q->tail"<<Q->tail<<endl;
    		Q->data[Q->tail++] = e;//
    		cout<<"not full"<<endl;
    	}
    	
    }
    //出
    void outQueue(SqQueue *Q)
    {
    	if(isQempty(Q) == 1)
    	{
    		cout<<"out queue empty"<<endl;
    		exit(0);
    	}
    	else
    	{
    		cout<<"out:"<<Q->data[Q->head++]<<endl;
    	}
    }
    
    
    
    /*void main()
    {
    	SqQueue S;
    	S=init(&S);
    	cout<<"isempty"<<isQempty(&S)<<endl;
    	inQueue(&S,1);
    	cout<<"isempty"<<isQempty(&S)<<endl;
    	inQueue(&S,2);
    	cout<<"isempty"<<isQempty(&S)<<endl;
    	outQueue(&S);
    	
    }*/
    

      

  • 相关阅读:
    Vue 下拉刷新及无限加载组件
    VUE常用问题hack修改
    CSS滤镜让图片模糊(毛玻璃效果)实例页面
    滑动删除
    拖动选择单元格并合并方法
    Windows7上开启ftp服务器功能
    js 向上滚屏
    理解Clip Path
    图标制作
    transition实现图片轮播
  • 原文地址:https://www.cnblogs.com/waiwai4701/p/4207937.html
Copyright © 2011-2022 走看看