Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
zhhf96
C-Plus-Plus-TheAlgorithms
提交
d6a5520b
C
C-Plus-Plus-TheAlgorithms
项目概览
zhhf96
/
C-Plus-Plus-TheAlgorithms
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
C-Plus-Plus-TheAlgorithms
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
d6a5520b
编写于
1月 16, 2020
作者:
D
danghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add a simple queue class
上级
ad23bbdf
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
174 addition
and
1 deletion
+174
-1
data_structure/queue/makefile
data_structure/queue/makefile
+11
-0
data_structure/queue/queue.cpp
data_structure/queue/queue.cpp
+90
-0
data_structure/queue/queue.h
data_structure/queue/queue.h
+34
-0
data_structure/queue/test_queue.cpp
data_structure/queue/test_queue.cpp
+38
-0
data_structure/stk/makefile
data_structure/stk/makefile
+1
-1
未找到文件。
data_structure/queue/makefile
0 → 100644
浏览文件 @
d6a5520b
CC
=
g++
CFLAGS
=
-c
-Wall
all
:
test_queue
queue.o
:
queue.cpp
$(CC)
$(CFLAGS)
queue.cpp
test_queue
:
queue.o
$(CC)
test_queue.cpp queue.o
-o
queue
clean
:
rm
*
o queue
data_structure/queue/queue.cpp
0 → 100644
浏览文件 @
d6a5520b
#include <iostream>
#include <assert.h>
#include "queue.h"
using
namespace
std
;
/* Default constructor*/
template
<
class
Kind
>
queue
<
Kind
>::
queue
()
{
queueFront
=
NULL
;
queueRear
=
NULL
;
size
=
0
;
}
/* Destructor */
template
<
class
Kind
>
queue
<
Kind
>::~
queue
()
{
}
/* Display for testing */
template
<
class
Kind
>
void
queue
<
Kind
>::
display
()
{
node
<
Kind
>
*
current
=
queueFront
;
cout
<<
"Front --> "
;
while
(
current
!=
NULL
)
{
cout
<<
current
->
data
<<
" "
;
current
=
current
->
next
;
}
cout
<<
endl
;
cout
<<
"Size of queue: "
<<
size
<<
endl
;
}
/* Determine whether the queue is empty */
template
<
class
Kind
>
bool
queue
<
Kind
>::
isEmptyQueue
()
{
return
(
queueFront
==
NULL
);
}
/* Clear queue */
template
<
class
Kind
>
void
queue
<
Kind
>::
clear
()
{
queueFront
=
NULL
;
}
/* Add new item to the queue */
template
<
class
Kind
>
void
queue
<
Kind
>::
enQueue
(
Kind
item
)
{
node
<
Kind
>
*
newNode
;
newNode
=
new
node
<
Kind
>
;
newNode
->
data
=
item
;
newNode
->
next
=
NULL
;
if
(
queueFront
==
NULL
)
{
queueFront
=
newNode
;
queueRear
=
newNode
;
}
else
{
queueRear
->
next
=
newNode
;
queueRear
=
queueRear
->
next
;
}
size
++
;
}
/* Return the top element of the queue */
template
<
class
Kind
>
Kind
queue
<
Kind
>::
front
()
{
assert
(
queueFront
!=
NULL
);
return
queueFront
->
data
;
}
/* Remove the element of the queue */
template
<
class
Kind
>
void
queue
<
Kind
>::
deQueue
()
{
node
<
Kind
>
*
temp
;
if
(
!
isEmptyQueue
())
{
temp
=
queueFront
;
queueFront
=
queueFront
->
next
;
delete
temp
;
size
--
;
}
else
{
cout
<<
"Queue is empty !"
<<
endl
;
}
}
data_structure/queue/queue.h
0 → 100644
浏览文件 @
d6a5520b
/* This class specifies the basic operation on a queue as a linked list */
#ifndef QUEUE_H
#define QUEUE_H
/* Definition of the node */
template
<
class
Kind
>
struct
node
{
Kind
data
;
node
<
Kind
>
*
next
;
};
/* Definition of the queue class */
template
<
class
Kind
>
class
queue
{
public:
void
display
();
/* Show queue */
queue
();
/* Default constructor*/
~
queue
();
/* Destructor */
bool
isEmptyQueue
();
/* Determine whether the queue is empty */
void
enQueue
(
Kind
item
);
/* Add new item to the queue */
Kind
front
();
/* Return the first element of the queue */
void
deQueue
();
/* Remove the top element of the queue */
void
clear
();
private:
node
<
Kind
>
*
queueFront
;
/* Pointer to the front of the queue */
node
<
Kind
>
*
queueRear
;
/* Pointer to the rear of the queue */
int
size
;
};
#endif
data_structure/queue/test_queue.cpp
0 → 100644
浏览文件 @
d6a5520b
#include <iostream>
#include <string>
#include "queue.h"
#include "queue.cpp"
using
namespace
std
;
int
main
()
{
queue
<
string
>
q
;
cout
<<
"---------------------- Test construct ----------------------"
<<
endl
;
q
.
display
();
cout
<<
"---------------------- Test isEmptyQueue ----------------------"
<<
endl
;
if
(
q
.
isEmptyQueue
())
cout
<<
"PASS"
<<
endl
;
else
cout
<<
"FAIL"
<<
endl
;
cout
<<
"---------------------- Test enQueue ----------------------"
<<
endl
;
cout
<<
"After Hai, Jeff, Tom, Jkingston go into queue: "
<<
endl
;
q
.
enQueue
(
"Hai"
);
q
.
enQueue
(
"Jeff"
);
q
.
enQueue
(
"Tom"
);
q
.
enQueue
(
"Jkingston"
);
q
.
display
();
cout
<<
"---------------------- Test front ----------------------"
<<
endl
;
string
value
=
q
.
front
();
if
(
value
==
"Hai"
)
cout
<<
"PASS"
<<
endl
;
else
cout
<<
"FAIL"
<<
endl
;
cout
<<
"---------------------- Test deQueue ----------------------"
<<
endl
;
q
.
display
();
q
.
deQueue
();
q
.
deQueue
();
cout
<<
"After Hai, Jeff left the queue: "
<<
endl
;
q
.
display
();
return
0
;
}
data_structure/stk/makefile
浏览文件 @
d6a5520b
CC
=
g++
CFLAGS
=
-c
-Wall
all
:
clean
main test_stack
all
:
main test_stack
stack.o
:
stack.cpp
$(CC)
$(CFLAGS)
stack.cpp
test_stack
:
stack.o
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录