Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create golang practice code #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions golang practice code
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main
import "fmt"

type node struct {
data int
next *node
}

type linkedList struct {
head *node
length int

}

func (l *linkedList) prepend (n *node) {
second := l.head
l.head = n
l.head.next = second
l.length++
}

func ( l linkedList) printListData(){
toPrint := l.head
for l. length != 0{
fmt.Printf("%d ", toPrint.data)
toPrint = toPrint.next
l.length--
}
fmt.Printf("\n")
}

func (l *linkedList) deleteWithValue(value int){
previousToDelete := l.head
for previousToDelete.next.data != value{
previousToDelete = previousToDelete.next
}
previousToDelete.next = previousToDelete.next.next
l.length--
}


func main(){
mylist := linkedList{}
mylist.printListData()
mylist.deleteWithValue(20)
mylist.printListData()
}