C/C++知识回顾 队列的出队和入队
2017-03-06 21:53
239 查看
#include<iostream> using namespace std; typedef struct student { int data; struct student *next; }node; typedef struct linkqueue { node *first, *rear; }queue; //入队 queue * push(queue * Q, int num) { node *s = (node *)malloc(sizeof(node)); s->data = num; s->next = NULL; if (Q->first==NULL) { Q->first = s; Q->rear = s; } else { Q->rear -> next = s; Q->rear = s; } return Q; } //出队 int pop(queue * Q) { if (Q->first==NULL) { cout << "队列为空" << endl; return -1; } else { int x = Q->first->data; node *p = Q->first; if (p==Q->rear) { Q->first = NULL; Q->rear = NULL; } else { Q->first = Q->first->next; free(p); return x; } } } int main() { }
相关文章推荐
- 【C++】容器适配器实现队列Queue的各种功能(入队、出队、判空、大小、访问所有元素等)
- 队列的入队,出队,测长度,打印c++代码
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果
- 队列的入队,出队,测长度,打印c++代码
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果
- C++ 知识回顾总结 -- queue 队列容器
- 队列的入队,出队,测长度,打印c++代码
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果
- 队列的入队,出队,测长度,打印c++代码
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果
- 【C++】容器适配器实现队列Queue的各种功能(入队、出队、判空、大小、访问所有元素等)
- 循环队列的定义、入队、出队等操作 C++代码实现
- 队列的入队,出队,测长度,打印c++代码
- 队列的入队,出队,测长度,打印c++代码
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果
- (10.15)[转]C++学习(队列操作,入队,出队)
- 队列的入队,出队,测长度,打印c++代码
- 队列的入队,出队,测长度,打印c++代码
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果
- 数据结构之队列的基本操作入队出队初始化删除-c++代码实现及运行实例结果