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

Sign up
Appearance settings

Commit 0e83abe

Browse files
refact +
1 parent bb271d9 commit 0e83abe

File tree

4 files changed

+50
-48
lines changed

4 files changed

+50
-48
lines changed

‎queue/queue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func main() {
1111
list := util.RandomInt() // срез int
1212
fmt.Printf("List:\t%v\n", list)
1313

14-
q := queue.QueueNew()
14+
q := queue.New()
1515
fmt.Println("Len Queue: ", q.Len())
1616

1717
fmt.Println("Enqueue:")

‎stack/stack.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ func main() {
1111
list := util.RandomInt() // срез int
1212
fmt.Printf("List:\t%v\n", list)
1313

14-
s := stack.StackNew()
14+
s := stack.New()
1515
fmt.Println("Len Stack: ", s.Len())
1616

1717
fmt.Println("Push:")

‎util/queue/queue.go

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package queue
22

33
type (
4+
// Queue - очередь
45
Queue struct {
56
start, end *node
67
length int
@@ -11,49 +12,49 @@ type (
1112
}
1213
)
1314

14-
// Create a new queue
15-
func QueueNew() *Queue {
15+
// New - Create a new queue
16+
func New() *Queue {
1617
return &Queue{nil, nil, 0}
1718
}
1819

19-
// Take the next item off the front of the queue
20-
func (this *Queue) Dequeue() interface{} {
21-
if this.length == 0 {
20+
// Dequeue - Take the next item off the front of the queue
21+
func (que *Queue) Dequeue() interface{} {
22+
if que.length == 0 {
2223
return nil
2324
}
24-
n := this.start
25-
if this.length == 1 {
26-
this.start = nil
27-
this.end = nil
25+
n := que.start
26+
if que.length == 1 {
27+
que.start = nil
28+
que.end = nil
2829
} else {
29-
this.start = this.start.next
30+
que.start = que.start.next
3031
}
31-
this.length--
32+
que.length--
3233
return n.value
3334
}
3435

35-
// Put an item on the end of a queue
36-
func (this *Queue) Enqueue(value interface{}) {
36+
// Enqueue - Put an item on the end of a queue
37+
func (que *Queue) Enqueue(value interface{}) {
3738
n := &node{value, nil}
38-
if this.length == 0 {
39-
this.start = n
40-
this.end = n
39+
if que.length == 0 {
40+
que.start = n
41+
que.end = n
4142
} else {
42-
this.end.next = n
43-
this.end = n
43+
que.end.next = n
44+
que.end = n
4445
}
45-
this.length++
46+
que.length++
4647
}
4748

48-
// Return the number of items in the queue
49-
func (this *Queue) Len() int {
50-
return this.length
49+
// Len - Return the number of items in the queue
50+
func (que *Queue) Len() int {
51+
return que.length
5152
}
5253

53-
// Return the first item in the queue without removing it
54-
func (this *Queue) Peek() interface{} {
55-
if this.length == 0 {
54+
// Peek - Return the first item in the queue without removing it
55+
func (que *Queue) Peek() interface{} {
56+
if que.length == 0 {
5657
return nil
5758
}
58-
return this.start.value
59+
return que.start.value
5960
}

‎util/stack/stack.go

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package stack
22

33
type (
4+
// Stack - список элементов
45
Stack struct {
56
top *node
67
length int
@@ -11,39 +12,39 @@ type (
1112
}
1213
)
1314

14-
// Create a new stack
15-
func StackNew() *Stack {
15+
// New - Create a new stack
16+
func New() *Stack {
1617
return &Stack{nil, 0}
1718
}
1819

19-
// Return the number of items in the stack
20-
func (this *Stack) Len() int {
21-
return this.length
20+
// Len - Return the number of items in the stack
21+
func (st *Stack) Len() int {
22+
return st.length
2223
}
2324

24-
// View the top item on the stack
25-
func (this *Stack) Peek() interface{} {
26-
if this.length == 0 {
25+
// Peek - View the top item on the stack
26+
func (st *Stack) Peek() interface{} {
27+
if st.length == 0 {
2728
return nil
2829
}
29-
return this.top.value
30+
return st.top.value
3031
}
3132

32-
// Pop the top item of the stack and return it
33-
func (this *Stack) Pop() interface{} {
34-
if this.length == 0 {
33+
// Pop - the top item of the stack and return it
34+
func (st *Stack) Pop() interface{} {
35+
if st.length == 0 {
3536
return nil
3637
}
3738

38-
n := this.top
39-
this.top = n.prev
40-
this.length--
39+
n := st.top
40+
st.top = n.prev
41+
st.length--
4142
return n.value
4243
}
4344

44-
// Push a value onto the top of the stack
45-
func (this *Stack) Push(value interface{}) {
46-
n := &node{value, this.top}
47-
this.top = n
48-
this.length++
45+
// Push - a value onto the top of the stack
46+
func (st *Stack) Push(value interface{}) {
47+
n := &node{value, st.top}
48+
st.top = n
49+
st.length++
4950
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /