master
Furkan Türkal 5 years ago
parent 064fc9c4af
commit d16fb68aae
No known key found for this signature in database
GPG Key ID: 3015FE56155820F2

@ -32,7 +32,7 @@ func New(data int) *Node {
func Search(root *Node, key int) *Node {
//1. Base Cases: root is null or key is present at root
if root == nil || root.data == key {
fmt.Println("The given previous node cannot be NULL")
//fmt.Println("The given previous node cannot be NULL")
return root
}

@ -29,7 +29,6 @@ func New(data int) *Node {
}
func main() {
//To allocate dynamically a new Node in C language : root = (struct Node*) malloc(sizeof(struct Node));
root := New(1)
/*

@ -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))
}

@ -61,7 +61,6 @@ func Pop(stack *Stack) int {
}
func main() {
stack := New(100)
Push(stack, 10)
@ -72,5 +71,4 @@ func main() {
fmt.Println("Pushed to stack : 30")
fmt.Printf("Popped from stack : %d", Pop(stack))
}
Loading…
Cancel
Save