update
parent
064fc9c4af
commit
d16fb68aae
Binary file not shown.
@ -0,0 +1 @@
|
||||
package main
|
@ -1,56 +0,0 @@
|
||||
// ====================================================
|
||||
// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal
|
||||
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
|
||||
// and you are welcome to redistribute it under certain conditions; See
|
||||
// file LICENSE, which is part of this source code package, for details.
|
||||
// ====================================================
|
||||
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
const MaxUint = ^uint(0)
|
||||
const MinUint = 0
|
||||
const MaxInt = int(MaxUint >> 1)
|
||||
const MinInt = -MaxInt - 1
|
||||
|
||||
type Stack struct {
|
||||
top int
|
||||
capacity uint
|
||||
array []int
|
||||
}
|
||||
|
||||
//Returns an initialized list
|
||||
func (s *Stack) Init(capacity uint) *Stack {
|
||||
s.top = -1
|
||||
s.capacity = capacity
|
||||
s.array = make([]int, capacity)
|
||||
return s
|
||||
}
|
||||
|
||||
//Returns an new list
|
||||
func New(capacity uint) *Stack {
|
||||
return new(Stack).Init(capacity)
|
||||
}
|
||||
|
||||
// Stack is full when top is equal to the last index
|
||||
func IsFull(stack *Stack) bool {
|
||||
return stack.top == int(stack.capacity)-1
|
||||
}
|
||||
|
||||
// Stack is empty when top is equal to -1
|
||||
func IsEmpty(stack *Stack) bool {
|
||||
return stack.top == -1
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
stack := New(100)
|
||||
|
||||
//Push(stack, 10)
|
||||
//Push(stack, 20)
|
||||
//Push(stack, 30)
|
||||
|
||||
fmt.Println("Popped from stack : %d", Pop(stack))
|
||||
|
||||
}
|
Loading…
Reference in New Issue