Go Programming Articles

Page 7 of 86

Golang Program to update the node value after the Kth node.

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 181 Views

ExamplesUpdate node after k=10 value nodeApproach 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 − Iterate the given linked list.Step 4 − If temp.value is 10, then update temp.next.value=data.Step 5 − If node value 10 is not found, return the head without updating any node.Examplepackage 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 } ...

Read More

Golang Program to update the node value after the Kth node (When K is not in the linked list).

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 154 Views

ExamplesUpdate node after k=50 value nodeApproach 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 − Iterate the given linked list.Step 4 − If node value 10 is not found, return the head without updating any node.Examplepackage 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 ...

Read More

Golang Program to update the ith index node value, when index is at 0 index.

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 178 Views

ExamplesApproach 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 − Initialize the index as i := 0.Step 4 − Iterate the given linked list from its head.Step 5 − If index i matches with given index (to be updated), then update that node.Step 6 − Else, return the head.Examplepackage 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 ...

Read More

Golang Program to update the ith index node value, when index is at the last index.

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 168 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 − Initialize the index as i := 0.Step 4 − Iterate the given linked list from its head.Step 5 − If index i matches with the given index (to be updated), then update that node.Step 6 − Else, return head.Examplepackage 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 ...

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 186 Views

ExamplesApproach to solve this problemStep 1 − Define a method that accepts head of the linked list.Step 2 − If head == nil, return the head.Step 3 − When index == 0, then return head.nextStep 4 − Else, Iterate given linked list from head.Step 5 − If index i matches with given index(to be delete) then delete that node.next, break the loop.Step 6 − Return, at the end of loop.Examplepackage 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 ...

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 11-Mar-2026 222 Views

ExamplesExampleApproach to solve this problempackage 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 {       fmt.Printf("%d ", temp.value)       temp = temp.next    }    fmt.Println() } func InsertNodeAtIthIndex(head *Node, index, data int) *Node{    if head == nil{       head = NewNode(data, nil)       return head    }    if index ...

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 11-Mar-2026 467 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 − Iterate the given linked list from its head. Also, initialize preNode that will keep the store address of the previous node.Step 5 − If index i matches with the given index, then then delete that node.next, break the loop.Step 6 − Return, at the end of loop.Examplepackage main import ...

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 549 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 until it becomes nil.Step 4 − Print temp.value.Examplepackage main import "fmt" type Node struct {    prev *Node    value int    next *Node } func CreateNewNode(value int) *Node{    var node Node    node.next = nil    node.value = value    node.prev = nil    return &node } func ...

Read More

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

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 4K+ 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.Examplepackage main import (    "fmt" ) func main(){    fmt.Printf("Enter size of your array: ")    var size int    fmt.Scanln(&size)    var arr = make([]int, size)    for i:=0; i

Read More

Golang program to traverse a given input array, with Boolean flag, using arrays and struct.

Rishikesh Kumar Rishi
Rishikesh Kumar Rishi
Updated on 11-Mar-2026 291 Views

ExampleApproachAsk the user to enter the size of array.Make a string array of given size.Ask the user to enter elements.At the end, print the array.Examplepackage main import "fmt" func main(){    arr := []int{10, 20, 30, 60, 40, 50}    boolArr := []bool{true, false, true, false, true, false}    fmt.Println("Input Array is: ", arr)    fmt.Println("Input Boolean Array is: ", boolArr)    visitedArray := []struct{       i int       b bool    }{       {10, true},       {20, false},       {30, true},       {60, false},       {40, true},       {50, false},    }    fmt.Println("Boolean array using struct: ", visitedArray) }OutputInput Array is: [10 20 30 60 40 50] Input Boolean Array is: [true false true false true false] Boolean array using struct: [{10 true} {20 false} {30 true} {60 false} {40 true} {50 false}]

Read More
Showing 61–70 of 852 articles
« Prev 1 5 6 7 8 9 86 Next »
Advertisements