Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 8 of 51

Golang Program to Create Two Goroutines

Akhil Sharma
Akhil Sharma
Updated on 13-Jul-2023 330 Views

When working with go language there may be instances where you need to create two goroutines for parallel processing, asynchronous operations and more. In this go language article we will explore how to create two goroutines using anonymous functions, named functions as well as using function calls.In golanguage a goroutine is an independent concurrent function, it enables concurrent programming by allowing the functions to run concurrently. Syntax time.Sleep(duration) It is a built-in go language function used to pause the execution of a program. It ...

Read More

Golang Program to Creates a Unidirectional Sending Channel and Passes it to a Function that Returns a Unidirectional Receiving Channel

Akhil Sharma
Akhil Sharma
Updated on 13-Jul-2023 206 Views

A unidirectional sending channel is used to send the values to the channel, while the unidirectional receiving channel is used to receive the data from the channel. These channels are used in concurrent data processing, data sharing and more. In this golang article we are going to create a program to create a unidirectional sending and pass it to a function that returns a unidirectional receiving channel using function parameters, type conversion as well as channel composition. Algorithm Define the sender Function that accepts a send-only channel named “ch” of type integer. ...

Read More

Golang Program to Find Average Paid Employee

Akhil Sharma
Akhil Sharma
Updated on 13-Jul-2023 203 Views

It is very important to know about the average salary paid to an employee in an organization for analysis, research and rewards. In this article we are going to find out the average employee salary in go language using iteration, reduce function as well as goroutines and channels. Algorithm CalculateAverage is a function that accepts a slice of float64 values salaries as input and returns a float64 value. Set the total to 0 and count the length of the salary slice. Using a ...

Read More

Golang program of two struct types with identical fields, with having one \"JSON\" tag on each field

Akhil Sharma
Akhil Sharma
Updated on 06-Jul-2023 1K+ Views

Struct types are used to construct custom data structures consist of fields. These fields reflect the structure's characteristics or attributes. The ability to add tags to fields, such as "JSON" tags, which offer additional metadata about the field when serializing or deserializing the struct to/from JSON format, is a valuable feature of struct types. In this article, we will write Go language programs to represent structs with one JSON tag in each field. type StructName struct { Field1 DataType1 `Tag1:"Value1" Tag2:"Value2"` Field2 DataType2 `Tag3:"Value3" Tag4:"Value4"` // ... ...

Read More

Golang program to compare two instances of this struct for equality, taking into account the values in the slice

Akhil Sharma
Akhil Sharma
Updated on 06-Jul-2023 350 Views

A struct is a counterpart to class in object-oriented programming where different fields can be placed in the struct, where these fields can be implemented later on and they have a type like int, float, string etc.In this article, we will write a Go language program to compare the equality of two structs. Syntax func len(v Type) int The len() method returns the length of any parameter. It accepts one input, the data type variable whose length we want to know. func range(variable) The range function iterates through any data type. To utilize this, we must first put ...

Read More

How to find the capacity of the pointers pointing at a map in Golang?

Akhil Sharma
Akhil Sharma
Updated on 06-Jul-2023 194 Views

A pointer is a variable which holds the address of another variable and can be used to point to the content of another variable. A pointer does not have its capacity just like slices, it can be used to point to the map whose length of elements can be calculated.In this article, we will write a Go language program to find the capacity of a pointer pointing to a map. 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 ...

Read More

Golang program to find the longest path in a weighted directed acyclic graph using Bellman-Ford algorithm

Akhil Sharma
Akhil Sharma
Updated on 06-Jul-2023 596 Views

In this article, we will write a Go language program to find the longest path in a weighted directed acyclic graph using Bellman-ford-algorithm. Bellman-Ford-Algorithm is a popular algorithm used to find the longest path from source vertex to other vertices in a weighted directed graph. Syntax func range(variable) Any data type may be iterated over using the range function. This may be used by first writing the range keyword, then the data type to which we wish to iterate. func make ([] type, size, capacity) When creating an array or map in the Go programming language, the ...

Read More

Golang program to find the minimum number of edges in a weighted directed graph that connects all nodes

Akhil Sharma
Akhil Sharma
Updated on 06-Jul-2023 235 Views

In this article, we will write Go language programs to find the minimum no. of edges in a weighted directed graph that connects all nodes. We will use Prim’s algorithm to perform this operation. It is a greedy algorithm which is used to find the minimum spanning tree for a graph. Syntax func range(variable) Any data type may be iterated over using the range function. This may be used by first writing the range keyword, then the data type to which we wish to iterate func make ([] type, size, capacity) The go language's make function is used ...

Read More

Golang program to perform a left rotation in a Red Black Tree

Akhil Sharma
Akhil Sharma
Updated on 06-Jul-2023 191 Views

A red black tree is a self balancing binary search tree. Rotation is one of the fundamental operations of a self balancing tree. It is performed to maintain the tree's properties while inserting and deleting nodes to the tree. In this article we are going to write a language program to perform left rotation in a Red Black tree using pointers as well as using node value. Properties of Red Black tree Every node is either red or black The root node is always black Every leaf node is considered black If a node is red, both its children ...

Read More

Golang program to find which Employees should get bonus

Akhil Sharma
Akhil Sharma
Updated on 06-Jul-2023 140 Views

In corporate office there may be some cases in which you have a list of employees and you need to provide them extra bonus based on the work or experience or a particular property. In this article we are going to explore a way to calculate bonus using performance based calculations and tenure based calculations. Method 1: Performance Based Calculations Performance is the common base to determine the employee’s bonus, in this method we are going to calculate the bonus depending on the performance of the employee. Algorithm Create the Employee struct, which has the values Name, Salary, and ...

Read More
Showing 71–80 of 507 articles
« Prev 1 6 7 8 9 10 51 Next »
Advertisements