Found 1082 Articles for Go Programming

Golang program to check a graph is bipartite using DFS

Akhil Sharma
Updated on 05-Apr-2023 15:18:02

139 Views

The Depth-First Search (DFS) Algorithm is a classic Algorithm used to traverse and search graphs. In this article we are going to learn how to develop golang program where we can check if a graph is bipartie or not using DFS . Here we will use two different approaches to implement the result. Syntax func len(v Type) int The len() function is used to get the length of a any parameter. It takes one parameter as the data type variable whose length we wish to find and returns the integer value which is the length of the variable. ... Read More

Golang program to implement radix sort

Akhil Sharma
Updated on 05-Apr-2023 15:17:20

294 Views

In this article we are going to understand how to use least significant bit and the most significant bit to implement radix sort. Radix sort is a sorting Algorithm that sorts elements by grouping them based on their individual digits or by the position of their digits. It is a linear time sorting Algorithm that has a time complexity of O(nk). Using the Least Significant Bit In this method, we will write a go language program to implement the radix sort by using the least significant bit. LSD sorts the elements from right to left by comparing their individual ... Read More

Implement tower of hanoi in Golang

Akhil Sharma
Updated on 05-Apr-2023 15:16:03

275 Views

In this article we are going to learn how to use recursion method and iteration to implement tower of hanoi in golang. The Tower of Hanoi is a puzzle in which we move a set of disks from one page to another by moving one disk at a time. There are certain set of rules that need to be obeyed in this puzzle. Using Recursion Approach In this method, we will write a go language program to implement tower of Hanoi by using the method of recursion. If n is 1, we can move the disk from from to ... Read More

Golang program to find all paths in a graph

Akhil Sharma
Updated on 05-Apr-2023 15:14:55

493 Views

In this article we are going to learn how to use DFS Algorithm and breath-first searh method in golang to find all the paths in the a graph. In a graph, the nodes are depicted by the entities while the edges depict the relation between those entities. Finding all paths in a graph is a common task in graph theory and can be useful in a variety of applications. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Then create different structs and functions and define properties to them. Step 3 − Now, ... Read More

Golang program to count number of nodes in a circular linked list

Akhil Sharma
Updated on 05-Apr-2023 15:10:16

134 Views

In golang, circular linked lists are an important data structure used in computer science to efficiently manage memory and data. A circular linked list is a linked list in which the last node of the list points to the first node of the list, creating a loop. Using Traversal Method In this method, we will write a go language program to count the number of nodes in a circular linked list by traversing through it. Algorithm Step 1 − First, we need to import the fmt package. Step 2 − Now, initialize a node struct and assign two ... Read More

Golang program to print pointer to a struct

Akhil Sharma
Updated on 04-Apr-2023 12:10:14

2K+ Views

In this article, we will write Golang programs to print pointer to a struct. A pointer stores the address of the memory location where the variable’s value is placed. We can the access the address of the variable using & operator. For ex= &a tell the address of the a. Example 1 In this example, we will write a Golang program to show the pointer to a struct by creating a child struct and printing the pointer to that struct. package main import "fmt" type Child struct { name string age ... Read More

Golang program to demonstrate passing of pointers to a function

Akhil Sharma
Updated on 04-Apr-2023 12:09:16

174 Views

In this Golang article, we will write programs to demonstrate passing of pointers to a function suing increment and Swapping approach. A pointer stores the address of another variable. For ex- var *a = &b. Here a is the pointer that stores the address of b which means a can access the value of b as it stores the address of b. Using the Increment Approach In this method, we will write a Golang program to demonstrate the passing of pointers to a function by using an increment function where we use pointers to point to the variable which is ... Read More

Golang program to implement returning pointer from a function

Akhil Sharma
Updated on 04-Apr-2023 12:08:17

530 Views

In this article, we will write Golang programs to implement returning pointer from a function. A pointer stores the address of another variable and the address is depicted using & operator. Algorithm Step 1 − Create a package main and declare fmt(format package) package in the program where main produces executable codes and fmt helps in formatting input and Output. Step 2 − Create a function create_pointer that returns a pointer to the int Step 3 − Set the value of x in the function and return the variable back to the function Step 4 − Create a main ... Read More

Golang program to parse time

Akhil Sharma
Updated on 04-Apr-2023 12:07:54

1K+ Views

In golang we can use various internal time function to parse time. Time is parsed using parse and ParseInLocation method. Syntax time.Parse() This function belongs to time package. It is used to parse the string into time.Time value and it takes two inputs: the layout and the time string which is to be parsed. time.ParselnLocation() This function is a part of the time package. It is used to parse the string into time.Time value along with a specified location. It takes 3 arguments: the location, layout string and the time string. time.Format() This function is present in ... Read More

Golang program to implement select statement

Akhil Sharma
Updated on 04-Apr-2023 12:07:17

240 Views

The Golang Select statement is similar to the switch statement, the switch statement selects the Output based on the cases but here the Output is selected based on which communication occurs fast in the channels. Syntax func make ([] type, size, capacity) The make function in go language is used to create an array/map it accepts the type of variable to be created, its size and capacity as arguments. time.Sleep() This function belongs to the time package. Here, the word sleep depicts the meaning of the function which says that it will block the execution of goroutine for ... Read More

Advertisements