链式队列
来源:互联网 发布:playclub陈诗涵mod数据 编辑:程序博客网 时间:2024/06/01 09:18
//============================================================================
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Graph.h"
#include <stdio.h>
#include <vector>
#include <cstring>
#include <vector>
#include<stdlib.h>
#include<assert.h>
#include <ctype.h>
using namespace std;
#define MAXSIZE 100
struct Node {
char data;
Node* next;
};
struct Queue {
Node* front;
Node* rear;
};
Queue InitQueue() {
Queue q;
Node* node = new Node;
node->next = NULL;
q.front = node;
q.rear = node;
return q;
}
void InQueue(Queue* q, char c) {
Node* node = new Node;
node->data = c;
node->next = NULL;
q->rear->next = node;
q->rear = node;
}
void OutQueue(Queue* q) {
if (q->front != q->rear) {
Node* node = q->front->next;
q->front->next = q->front->next->next;
delete node;
if(q->front->next==NULL)
{
q->front=q->rear;
}
}
}
void showQueue(Queue* q) {//显示队列
if(q->front!=q->rear)
{
Node* node=q->front->next;
int i=0;
while(node!=NULL)
{
cout<<node->data<<i++;
node=node->next;
}
}
}
int main() {
Queue q = InitQueue();
char a[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','\0' };
int len = strlen(a);
cout<<len;
for (int i = 0; i < len; i++) {
if (i > 0 && (i % 24 == 0)) {
OutQueue(&q);
} else {
InQueue(&q, a[i]);
}
}
showQueue(&q);
return 0;
}
// Name : C++Study.cpp
// Author : pan
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include <iostream>
#include "Graph.h"
#include <stdio.h>
#include <vector>
#include <cstring>
#include <vector>
#include<stdlib.h>
#include<assert.h>
#include <ctype.h>
using namespace std;
#define MAXSIZE 100
struct Node {
char data;
Node* next;
};
struct Queue {
Node* front;
Node* rear;
};
Queue InitQueue() {
Queue q;
Node* node = new Node;
node->next = NULL;
q.front = node;
q.rear = node;
return q;
}
void InQueue(Queue* q, char c) {
Node* node = new Node;
node->data = c;
node->next = NULL;
q->rear->next = node;
q->rear = node;
}
void OutQueue(Queue* q) {
if (q->front != q->rear) {
Node* node = q->front->next;
q->front->next = q->front->next->next;
delete node;
if(q->front->next==NULL)
{
q->front=q->rear;
}
}
}
void showQueue(Queue* q) {//显示队列
if(q->front!=q->rear)
{
Node* node=q->front->next;
int i=0;
while(node!=NULL)
{
cout<<node->data<<i++;
node=node->next;
}
}
}
int main() {
Queue q = InitQueue();
char a[] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z','\0' };
int len = strlen(a);
cout<<len;
for (int i = 0; i < len; i++) {
if (i > 0 && (i % 24 == 0)) {
OutQueue(&q);
} else {
InQueue(&q, a[i]);
}
}
showQueue(&q);
return 0;
}
0 0
- 链式队列
- 链式队列
- 链式队列
- 链式队列
- 队列--链式
- 链式队列
- 链式队列
- 链式队列
- 链式队列
- 链式队列
- 队列-链式
- 链式队列
- 链式队列
- 链式队列
- 链式队列
- 链式队列
- 链式队列
- 链式队列
- C语言中关于进程的函数
- centos 7 密码忘记 如何进入修改
- 深入理解PHP之数组(遍历顺序)
- GMT和CST的转换
- linux下weblogic11g安装成功后,启动报错Getting boot identity from user
- 链式队列
- 防SQL注入
- 学习网址
- 使用系统下载管理类DownloadManager
- 【Leetcode Algorithm】Rectangle Area
- 关于交叉编译器默认体系结构的问题
- 攻克GRE阅读难关的方法
- 润乾填报表的时间参数设置
- 【Leetcode Algorithm】Invert Binary Tree