forked from TheAlgorithms/Go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstackarray.go
39 lines (32 loc) · 1.14 KB
/
stackarray.go
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
// Stack Array
// description: based on `geeksforgeeks` description Stack is a linear data structure which follows a particular order in which the operations are performed.
// The order may be LIFO(Last In First Out) or FILO(First In Last Out).
// details:
// Stack Data Structure : https://www.geeksforgeeks.org/stack-data-structure-introduction-program/
// Stack (abstract data type) : https://en.wikipedia.org/wiki/Stack_(abstract_data_type)
// author [Milad](https://github.com/miraddo)
// see stacklinkedlist.go, stacklinkedlistwithlist.go, stack_test.go
package stack
var stackArray []interface{}
// stackPush push to first index of array
func stackPush(n interface{}) {
stackArray = append([]interface{}{n}, stackArray...)
}
// stackLength return length of array
func stackLength() int {
return len(stackArray)
}
// stackPeak return last input of array
func stackPeak() interface{} {
return stackArray[0]
}
// stackEmpty check array is empty or not
func stackEmpty() bool {
return len(stackArray) == 0
}
// stackPop return last input and remove it in array
func stackPop() interface{} {
pop := stackArray[0]
stackArray = stackArray[1:]
return pop
}