Programming Articles - Page 1289 of 3366

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

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:57:21

204 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 index i matches with the given index (to be deleted), then delete that node.next, break the loop.Step 6 − Return, at the end of the loop.Example Live Demopackage main import "fmt" type Node struct {    value int    next *Node } func NewNode(value int, next *Node) *Node{    var n ... Read More

Golang program to delete the ith index node, when the index is the last index in the linked list.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:55:37

115 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 − When index == 0, then return head.nextStep 4 − Else, iterate the given linked list from its head.Step 5 − If index i matches with the given index (to be deleted), then delete that node.next, break the loop.Step 6 − Return at the end of the loop.Example Live Demopackage main import "fmt" type Node struct {    value int    next *Node } func NewNode(value int, next *Node) *Node{    var n ... Read More

Golang program to delete the ith index node, when the index is at the mid-index level in the linked list.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:53:28

149 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 head.Step 5 − If index i matches with the given index (to be deleted), then delete that node.next, break the loop.Step 6 − Return at the end of the loop.Example Live Demopackage main import "fmt" type Node struct {    value int    next *Node } func NewNode(value int, next *Node) *Node{    var n Node ... Read More

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

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:50:13

118 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.Example 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   ... Read More

Golang Program to traverse a given tree in Postorder Traversal (Recursive).

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:46:29

316 Views

ExampleSuppose we have the following binary tree.Postorder Tree Traversal Output − 2 4 5 3 6 7 1.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 − Traverse the Left sub-tree.Step 3 − Traverse the Right sub-tree.Step 4 − Print the root node data.Example Live Demopackage main import "fmt" type Node struct {    data int    left *Node    right *Node } func (root *Node)PostOrderTraversal(){    if root !=nil{       root.left.PostOrderTraversal()       root.right.PostOrderTraversal()       fmt.Printf("%d ", root.data) ... Read More

Golang program to update the ith index node value, when index is at the nth position, i.e., out of index bound.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:44:32

100 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.Example 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 = ... Read More

Golang program to update the ith index node value, when the index is at 2, i.e., mid index.

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:42:49

107 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 the index i matches with the given index (to be updated), then update that node.Step 6 − Else, return head.Example 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 ... Read More

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

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:38:18

123 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.Example 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 = ... Read More

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

Rishikesh Kumar Rishi
Updated on 18-Mar-2021 11:36:29

122 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.Example 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 = ... Read More

Calculating the root mean square of all pixels for each band in an image using the Pillow library

Prasad Naik
Updated on 18-Mar-2021 07:19:49

828 Views

In this program, we will calculate the rms (root mean square) of all the pixels in each channel using the Pillow library. There are a total three channels in an image and therefore, we will get a list of three values.Original ImageAlgorithmStep 1: Import the Image and ImageStat libraries. Step 2: Open the image. Step 3: Pass the image to the stat function of the imagestat class. Step 4: Print the root mean square of the pixels.Example Codefrom PIL import Image, ImageStat im = Image.open('image_test.jpg') stat = ImageStat.Stat(im) print(stat.rms)Output[104.86876722259062, 96.13661429330132, 91.8480515464677]

Advertisements