FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
structures-algorithm/structures/queue/queue.go at master · FishGold/structures-algorithm · GitHub
FishGold
/
structures-algorithm
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
2
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
structures-algorithm
/
structures
/
queue
/
queue.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (72 loc) · 1.4 KB
Breadcrumbs
structures-algorithm
/
structures
/
queue
/
queue.go
Copy path
File metadata and controls
85 lines (72 loc) · 1.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package
queue
import
"errors"
type
ElementType
interface
{}
type
Array
[]
ElementType
func
New
(
cap
int
)
*
Queue
{
data
:=
make
(
Array
,
cap
)
return
&
Queue
{
Capacity
:
cap
,
Front
:
1
,
Rear
:
0
,
Size
:
0
,
Data
:
&
data
,
}
}
type
QueueInterface
interface
{
IsEmpty
()
bool
IsFull
()
bool
MakeEmpty
()
EnQueue
(
x
ElementType
)
error
DeQueue
() (
ElementType
,
error
)
}
/* Queue implementation with Slice */
type
Queue
struct
{
Capacity
int
Front
int
Rear
int
Size
int
Data
*
Array
}
/* Return true if queue is empty */
func
(
s
*
Queue
)
IsEmpty
()
bool
{
return
s
.
Size
==
0
}
/* Return true if the queue is full*/
func
(
s
*
Queue
)
IsFull
()
bool
{
return
s
.
Size
==
s
.
Capacity
}
/* Make queue Empty */
func
(
s
*
Queue
)
MakeEmpty
() {
s
.
Front
=
1
s
.
Rear
=
0
s
.
Size
=
0
empty_slice
:=
(
*
s
.
Data
)[:
0
]
s
.
Data
=
&
empty_slice
}
/* Push x enter queue at rear*/
func
(
s
*
Queue
)
EnQueue
(
x
ElementType
)
error
{
if
s
.
IsFull
() {
return
errors
.
New
(
"full queue"
)
}
s
.
Rear
=
s
.
succ
(
s
.
Rear
)
(
*
s
.
Data
)[
s
.
Rear
]
=
x
s
.
Size
++
return
nil
}
/*Get and delete x from queue at front */
func
(
s
*
Queue
)
DeQueue
() (
ElementType
,
error
) {
if
s
.
IsEmpty
() {
return
nil
,
errors
.
New
(
"empty queue"
)
}
x
:=
(
*
s
.
Data
)[
s
.
Front
]
s
.
Front
=
s
.
succ
(
s
.
Front
)
s
.
Size
--
return
x
,
nil
}
/* Enhance value circulate */
func
(
s
*
Queue
)
succ
(
value
int
)
int
{
if
value
++
;
s
.
Capacity
==
value
{
value
=
0
}
return
value
}
Back
|
FazBrowse Home
|
New Git URL