链式队列

来源:互联网 发布: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;
}
0 0
原创粉丝点击