Rishikesh Kumar Rishi has Published 1162 Articles

Golang Program to create a string array that takes inputs from users.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:23:25

793 Views

ExampleApproachAsk the user to enter the size of array.Make a string array of given size.Ask the user to enter the elements.At the end, print the array.Example Live Demopackage main import (    "fmt" ) func main(){    fmt.Printf("Enter size of your array: ")    var size int    fmt.Scanln(&size)    var ... Read More

Golang program to create an integer array that takes inputs from users.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:21:49

3K+ Views

ExampleApproachAsk the user to enter the size of array.Make an integer array of given size.Ask the user to enter elements.At the end, print the array.Example Live Demopackage main import (    "fmt" ) func main(){    fmt.Printf("Enter size of your array: ")    var size int    fmt.Scanln(&size)    var arr ... Read More

Golang program to count the number of nodes in a doubly linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:19:51

97 Views

ExamplesApproachStep 1 − Define a method that accepts the head of a doubly linked list.Step 2 − Initialize temp:=head, count:=0Step 3 − Iterate temp until it becomes nil.Step 4 − Increase count by 1.Step 5 − At the end, print count.Example Live Demopackage main import "fmt" type Node struct {   ... Read More

Golang Program to create a doubly linked list and traverse forward.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:17:47

367 Views

A doubly linked list node contains three items, where two items point to the next and previous nodes, and the third item contains the value of that node.ExampleApproachStep 1 − Define a method that accepts the head of a doubly linked list.Step 2 − Initialize temp:=head.Step 3 − Iterate temp ... Read More

Golang program to insert a node at the ith index node, when the index is at the last position in the linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:16:15

95 Views

ExamplesExampleApproach to solve this problem Live Demopackage main import "fmt" type Node struct {    value int    next *Node } func NewNode(value int, next *Node) *Node{    var n Node    n.value = value    n.next = next    return &n } func TraverseLinkedList(head *Node){    temp := head   ... Read More

Golang program to traverse a given tree in Inorder Traversal (Recursive).

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:14:16

240 Views

ExampleSuppose we have the following tree.Inorder Tree Traversal Output − 4 2 5 1 6 3 7Approach to solve this problemStep 1 − If the root node of the given tree is nil, then return; else, follow the steps given below.Step 2 − Traverse the Left sub-tree.Step 3 − Print ... Read More

Golang program to insert a node at the ith index node, when the index is at the nth index, i.e., out of bound in the linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:12:31

67 Views

ExamplesExample Live Demopackage main import "fmt" type Node struct {    value int    next *Node } func NewNode(value int, next *Node) *Node{    var n Node    n.value = value    n.next = next    return &n } func TraverseLinkedList(head *Node){    temp := head    for temp != nil ... Read More

Golang program to insert a node at the ith index node, when the index is at the mid-index position in the linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 12:07:49

63 Views

ExamplesExample Live Demopackage main import "fmt" type Node struct {    value int    next *Node } func NewNode(value int, next *Node) *Node{    var n Node    n.value = value    n.next = next    return &n } func TraverseLinkedList(head *Node){    temp := head    for temp != nil ... Read More

Golang Program to insert a node at the ith index node, when the index is at the 0th position in the linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 11:59:36

323 Views

ExamplesApproach to solve this problemStep 1 − Define a method that accepts the head of a linked list.Step 2 − If head == nil, create a new node and make it head and return it as the new head.Step 3 − When index == 0, then update the head.Step 4 ... Read More

Golang program to delete the ith index node, when index is the out of range in the linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 11:57:21

151 Views

ExampleApproach to solve this problemStep 1 − Define a method that accepts the head of a linked list.Step 2 − If head == nil, return the head.Step 3 − When index == 0, then return head.nextStep 4 − Else, iterate the given linked list from its head.Step 5 − If ... Read More

Advertisements