gostudent / Algorithms

Implementation of Data Structures and Algorithms in Go for Students
MIT License
28 stars 15 forks source link

Implement Important Data Structures in Go #5

Open mubaris opened 6 years ago

mubaris commented 6 years ago

Data Structures to consider:

anandwana001 commented 6 years ago

@mubaris trying for stack, will do PR soon

gauthamzz commented 6 years ago

sounds good @anandwana001

anandwana001 commented 6 years ago

@mubaris @gauthamzz I got busy with my exams but free now. Here I tried to make a stack in Go. please if you could give some feedback.

img_20180107_094056

package main

import "fmt"

type Stack struct {
    size int
    top *Node
}

type Node struct {
    value string
    next *Node
}

func (s *Stack) Length() int {
  return s.size
}

func (s *Stack) Push(val string) {
    s.top = &Node{val, s.top}
    fmt.Printf("%v pushed to stack\n",val)
    s.size++
}

func (s *Stack) Pop() (val string) {
  if s.size > 0 {
    val, s.top = s.top.value, s.top.next
    s.size--
    return 
  }
  return
}

func main() {
    stack := &Stack{}

    stack.Push("10")
    stack.Push("20")
    stack.Push("30")

    fmt.Println()

    for stack.Length() > 0 {
        fmt.Printf("%s popped from stack\n", stack.Pop())
    }
}
gauthamzz commented 6 years ago

send pr ,it looks good

pani-vishal commented 6 years ago

Is this for everyone, if not can it be assigned to me?

mubaris commented 6 years ago

As of now only Stack and Queue are implemented.

Each Data Structure will get 10 points. If you would like to take this issue, Take Each DS one by one and comment you're working on it.

pani-vishal commented 6 years ago

Alright I would like to work on making a linked list.

mubaris commented 6 years ago

@falconis Sure

ProBeta1 commented 6 years ago

May I work on Graph ?

gauthamzz commented 6 years ago

Yeah sure

namantw commented 6 years ago

Can I do the Binary Search tree?

gauthamzz commented 6 years ago

yea sure @namantw

marshallKR7 commented 6 years ago

@mubaris @gauthamzz done Linked List implementation through PR #22

arpitmisraw commented 6 years ago

I want to work on heaps.