FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
algorithms/data-structures/queue/queue.go at master · arnauddri/algorithms · GitHub
arnauddri
/
algorithms
Public
Notifications
You must be signed in to change notification settings
Fork
264
Star
1.8k
Code
Issues
10
Pull requests
10
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
algorithms
/
data-structures
/
queue
/
queue.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
58 lines (43 loc) · 802 Bytes
Breadcrumbs
algorithms
/
data-structures
/
queue
/
queue.go
Copy path
File metadata and controls
58 lines (43 loc) · 802 Bytes
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
package
queue
import
"sync"
type
Queue
struct
{
queue
[]
interface
{}
len
int
lock
*
sync.
Mutex
}
func
New
()
*
Queue
{
queue
:=
&
Queue
{}
queue
.
queue
=
make
([]
interface
{},
0
)
queue
.
len
=
0
queue
.
lock
=
new
(sync.
Mutex
)
return
queue
}
func
(
q
*
Queue
)
Len
()
int
{
//q.lock.Lock()
//defer q.lock.Unlock()
return
q
.
len
}
func
(
q
*
Queue
)
isEmpty
()
bool
{
q
.
lock
.
Lock
()
defer
q
.
lock
.
Unlock
()
return
q
.
len
==
0
}
func
(
q
*
Queue
)
Shift
() (
el
interface
{}) {
//q.lock.Lock()
//defer q.lock.Unlock()
el
,
q
.
queue
=
q
.
queue
[
0
],
q
.
queue
[
1
:]
q
.
len
--
return
}
func
(
q
*
Queue
)
Push
(
el
interface
{}) {
//q.lock.Lock()
//defer q.lock.Unlock()
q
.
queue
=
append
(
q
.
queue
,
el
)
q
.
len
++
return
}
func
(
q
*
Queue
)
Peek
()
interface
{} {
q
.
lock
.
Lock
()
defer
q
.
lock
.
Unlock
()
return
q
.
queue
[
0
]
}
Back
|
FazBrowse Home
|
New Git URL