#include<iostream>
using namespace std;
// 连队列
typedef struct Q {
int date;
struct Q *next;
}Q, *Qq;
typedef struct {
Qq front;
Qq rear;
}Link;
void gouzao(Link &L) {
L.front = L.rear = new Q;
if (!L.front) {
cout << "错误" << endl;
return;
}
L.front->next = NULL;
}
void charu(Link &L, int e) {
Qq n;
n = new Q;
if (!n) {
cout << "错误" << endl;
return;
}
n->date = e;
n->next = NULL;
L.rear->next = n;
L.rear = n;
}
void shuchu(Link &L) {
if (L.front == L.rear) {
cout << "kong" << endl;
return;
}
Qq p;
p = L.front->next;
cout << p->date << endl;
L.front->next = p->next;
if (L.rear == p) {
L.rear = L.front;
}
delete(p);
}
void xiaohui(Link &k) {
while (k.front) {
k.rear = k.front->next;
delete(k.front);
k.front = k.rear;
}
}
void bianli(Link L) {
Qq d;
d = L.front->next;
while (d) {
cout << d->date << '\t';
d = d->next;
}
cout << endl;
}
void changdu(Link L) {
int count = 0;
Qq d;
d = L.front->next;
while (d) {
count++;
d = d->next;
}
cout << count << endl;
}
int main() {
Link q;
int b[] = { 1,2,3,4,5,6,7,8,9 };
gouzao(q);
cout << q.front << q.rear << endl;
charu(q, 2);
cout << q.front->next->date;
shuchu(q);
for (int i = 0; i < 9; i++) {
charu(q, b[i]);
}
bianli(q); changdu(q);
cout << q.front->next << endl;
xiaohui(q);
cout << q.front << endl;
return 0;
}
浙公网安备 33010602011771号