From 9383bab22f7e0eebbe8296bb1bd3bdaa8efd9ebe Mon Sep 17 00:00:00 2001 From: abiraj1234 <102525826+abiraj1234@users.noreply.github.com> Date: Sat, 22 Oct 2022 12:40:04 +0530 Subject: [PATCH] Create golang practice code --- golang practice code | 47 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 golang practice code diff --git a/golang practice code b/golang practice code new file mode 100644 index 00000000..8f41c672 --- /dev/null +++ b/golang practice code @@ -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() +}