Rishikesh Kumar Rishi has Published 1156 Articles

Golang Program to update the first node value in a linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 06:09:03

224 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 − Else, update the first node value to 29.Example Live Demopackage main import "fmt" type Node struct {    value int    next ... Read More

Golang Program to delete the last node from a linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 06:06:36

449 Views

ExamplesApproach to solve this problem −Step 1 − Define a method that accepts the head of a linked list.Step 2 − If head == nil, return the head.Step 3 − Go to the next node and return the updated head.Example Live Demopackage main import (    "fmt" ) type Node struct ... Read More

Golang Program to delete the first node from a linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 06:04:41

618 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 − Go to the next node and return the updated head.Example Live Demopackage main import "fmt" type Node struct {    value int ... Read More

Golang Program to add a node at the end of a given linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 06:00:37

555 Views

ExampleNext5NullApproach 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 return that node.Step 3 − If head is not nil, traverse till the second last of the linked list.Example Live Demopackage main ... Read More

Golang Program to add the first node in a given linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 05:54:48

331 Views

ExampleApproach to solve this problemStep 1 − Define a method that accepts the head of the linked list.Step 2 − If head == nil, create a new node and return that node.Step 3 − If head is not nil, then update the head of the input linked list.Example Live Demopackage main ... Read More

Golang Program to reverse a given linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 05:50:09

2K+ Views

ExamplesApproach to solve this problemStep 1 − Define a method that accepts the head of a linked list.Step 2 − If head == nil, return; else, call ReverseLinkedList, recursively.Step 3 − Print head.value at the end.Example Live Demopackage main import "fmt" type Node struct {    value int    next *Node ... Read More

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

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 05:48:36

5K+ Views

ExamplesApproach to solve this problemStep 1 − Define a method that accepts the head of the linked list.Step 2 − Initialize a variable, count := 0.Step 3 − Iterate the given linked list till it reaches the last node.Step 4 − Increase the count by 1 in the loop.Step 5 ... Read More

Golang Program to define a singly linked list.

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 05:45:22

586 Views

ExamplesApproach to solve this problemStep 1 − Let’s define a structure of the node.Step 2 − Make the Linked List such that the previous node would store the address of the next node.Example Live Demopackage main import "fmt" type Node struct {    value int    next *Node } func NewNode(value ... Read More

Golang Program to convert an integer into binary representation

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 05:43:23

4K+ Views

ExamplesFor example, n = 1 (Binary Representation of 1: 1)For example, n = 5 (Binary Representation of 5: 101)For example, n = 20 (Binary Representation of 5: 10100)For example, n = 31 (Binary Representation of 31: 11111)Approach to solve this problemStep 1 − Define a method that accepts an integer, ... Read More

Golang Program to traverse a given binary tree in Preorder Traversal (Recursive)

Rishikesh Kumar Rishi

Rishikesh Kumar Rishi

Updated on 18-Mar-2021 05:40:47

664 Views

ExampleSuppose we have the following binary tree.Preorder Tree Traversal Output: 1, 2, 4, 5, 3, 6, 7.Approach 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 − Print the root node data.Step 3 − ... Read More

Advertisements