zoukankan      html  css  js  c++  java
  • 数据结构-链式结构-队列

    //#define _CRT_SECURE_NO_WARNINGS
    #include<stdio.h>
    #include<stdlib.h>
    #define MAXSIZE 100
    #define ERROR 0
    #define OK 1
    typedef int SElemType;
    typedef int Status;

    typedef int QElemType;
    //节点结构
    typedef struct QNode
    {
    QElemType data;
    struct QNode* next;
    }QNode, * QueuePtr;
    //队列结构
    typedef struct
    {
    //定义了头节点和尾节点
    QueuePtr front, rear;
    }LinkQueue;
    //入队
    Status EnQueue(LinkQueue* s, QElemType e)
    {
    QueuePtr temp = (QueuePtr)malloc(sizeof(QNode));
    //给要入队的数据申请内存
    if (temp == NULL)
    {
    return ERROR;
    }
    //给新要入队申请内存的结构体赋值
    temp->data = e;
    temp->next = NULL;
    //将结构体入队
    s->rear->next = temp;
    //将尾指针指向新入队的结构体
    s->rear = temp;
    return OK;
    }
    //出队
    Status DeQueue(LinkQueue* s, QElemType *e)
    {
    //判断队列是否为空
    if (s->front == s->rear)
    {
    return ERROR;
    }
    //建立临时节点指针
    QueuePtr temp;
    //给临时节点指针赋值
    temp = s->front->next;
    //给需要出队的内容赋值
    *e = temp->data;
    //偏移头指针指向的位置
    s->front->next = temp->next;
    if (s->rear == temp)//如果要出队的数据是尾节点指向的地址
    {
    //那么说明一个一个数据在队里,这个时候需要吧
    //头节点和尾节点的指向指向在一起
    s->rear = s->front;
    }
    free(temp);
    temp = NULL;
    return OK;
    }

  • 相关阅读:
    个税
    MC9S08中断机制
    各大公司面试笔试
    uc/OSII 任务切换
    Source Insight 使用
    充70送70
    兔年大年30
    pip更新后报No module named pip
    MsSql Md5
    iOS UIImage扩展方法(category):放大、旋转、合并UIImage、增加渐变层、添加阴影、调节透明度、保存到相册
  • 原文地址:https://www.cnblogs.com/beautiful7/p/14108400.html
Copyright © 2011-2022 走看看