8000 link queue: 链式队列的实现 · home-coder/data-abstraction-001@bdefaef · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bdefaef

Browse files
author
oneface
committed
link queue: 链式队列的实现
1 parent f1003d7 commit bdefaef

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed

004-lqueue.c

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/***************************************************************************
2+
> Filename : 004-lqueue.c
3+
> Author : oneface - one_face@sina.com
4+
> Company : 一尊还酹江月
5+
> Time : 2018-05-05 16:35:27
6+
> Description:
7+
8+
- This program is free software; you can redistribute it and/or modify it
9+
- under the terms of the GNU General Public License as published by the
10+
- Free Software Foundation; either version 2 of the License, or (at your
11+
- option) any later version.
12+
**************************************************************************/
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
16+
typedef struct _lqueue{
17+
char data;
18+
struct _lqueue *next;
19+
}lqueue;
20+
21+
static void init_lqueue(lqueue **front, lqueue **rear)
22+
{
23+
lqueue *head = (lqueue *)malloc(sizeof(lqueue));
24+
*front = *rear = head;
25+
}
26+
27+
static void en_lqueue(lqueue **rear, char da)
28+
{
29+
if (!*rear) {
30+
printf("lqueue is not init\n");
31+
return ;
32+
}
33+
lqueue *nq = (lqueue *)malloc(sizeof(lqueue));
34+
(*rear)->data = da;
35+
(*rear)->next = nq;
36+
*rear = nq;
37+
}
38+
39+
static void de_lqueue(lqueue **front, lqueue **rear)
40+
{
41+
if (!*front) {
42+
printf("lqueue is not init\n");
43+
return ;
44+
}
45+
46+
if (*front == *rear) {
47+
printf("队列已空\n");
48+
return ;
49+
}
50+
printf("de queue: %c\n", (*front)->data);
51+
lqueue *f = *front;
52+
(*front) = (*front)->next;
53+
free(f);
54+
}
55+
56+
int main()
57+
{
58+
lqueue *front, *rear;
59+
front = rear = NULL;
60+
61+
en_lqueue(&rear, 'a');
62+
de_lqueue(&front, &rear);
63+
64+
init_lqueue(&front, &rear);
65+
66+
de_lqueue(&front, &rear);
67+
en_lqueue(&rear, 'a');
68+
en_lqueue(&rear, 'b');
69+
en_lqueue(&rear, 'c');
70+
en_lqueue(&rear, 'd');
71+
en_lqueue(&rear, 'd');
72+
en_lqueue(&rear, 'b');
73+
en_lqueue(&rear, 'c');
74+
en_lqueue(&rear, 'd');
75+
en_lqueue(&rear, 'b');
76+
en_lqueue(&rear, 'c');
77+
en_lqueue(&rear, 'd');
78+
en_lqueue(&rear, 'b');
79+
en_lqueue(&rear, 'c');
80+
de_lqueue(&front, &rear);
81+
de_lqueue(&front, &rear);
82+
de_lqueue(&front, &rear);
83+
de_lqueue(&front, &rear);
84+
de_lqueue(&front, &rear);
85+
de_lqueue(&front, &rear);
86+
de_lqueue(&front, &rear);
87+
de_lqueue(&front, &rear);
88+
de_lqueue(&front, &rear);
89+
de_lqueue(&front, &rear);
90+
de_lqueue(&front, &rear);
91+
de_lqueue(&front, &rear);
92+
de_lqueue(&front, &rear);
93+
de_lqueue(&front, &rear);
94+
de_lqueue(&front, &rear);
95+
de_lqueue(&front, &rear);
96+
de_lqueue(&front, &rear);
97+
de_lqueue(&front, &rear);
98+
99+
return 0;
100+
}

Readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
[哈夫曼编码与解码(C语言实现)](http://touch-2011.iteye.com/blog/1058800)
3535
[优化的三叉哈夫曼树](https://blog.csdn.net/wbcg111/article/details/50998021)
3636
[哈夫曼树与哈夫曼编码(C语言代码实现)](https://blog.csdn.net/u012675150/article/details/43152483)
37+
[哈夫曼树以及文件压缩的实现](https://blog.csdn.net/qq_33951180/article/details/53229240)
3738

3839
---
3940
# 数据结构教程

0 commit comments

Comments
 (0)
0