Found 26504 Articles for Server Side Programming

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

Akhil Sharma
Updated on 06-Jul-2023 12:48:47

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

How do you compare two struct instances that have pointers as fields in Golang

Akhil Sharma
Updated on 06-Jul-2023 12:40:48

1K+ Views

In golang, Pointers are the variables which store the address of other variables. 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 two struct instances that have pointers as fields. Mathematical representation for assigning the address of variable “b” to variable “a” − a = &b & denotes the address of operator, and receives the memory address of ... Read More

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

Akhil Sharma
Updated on 06-Jul-2023 12:35:58

291 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
Updated on 06-Jul-2023 12:32:23

160 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
Updated on 06-Jul-2023 12:30:54

543 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
Updated on 06-Jul-2023 12:24:12

190 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 find the shortest path from a source node to a target node using the Bellman-Ford algorithm

Akhil Sharma
Updated on 06-Jul-2023 12:22:17

239 Views

Bellman-ford algorithm is used to find the shortest distance from the source node to the other nodes in a weighted directed graph. This algorithm also predicts the negative weight cycles in the graph. It has a time complexity of O(V*E) where V stands for vertices and E stands for edges.In this Golang article, we will write programs to find the shortest path from source node to a target node using the Bellman-ford algorithm. Syntax func range(variable) The range function iterates through any data type. To utilise this, first type the range keyword followed by the data type to which ... Read More

Golang program to implement radix sort for sorting floating-point numbers

Akhil Sharma
Updated on 06-Jul-2023 12:15:36

465 Views

In this article, we will write Go language programs to implement radix sort for sorting floating-point numbers. Radix sort is usually used for sorting the integers, it can also be used to sort floating point numbers. It sorts items based on their particular bits or digits. This article provides an effective approach to sort the floating point numbers using the representation of floating point numbers. Algorithm Step 1 − Convert the floating-point numbers to a sortable format Step 2 − Perform a Radix Sort for each digit position Step 3 − Sort the integers based on the current ... Read More

Golang program to implement radix sort for sorting strings

Akhil Sharma
Updated on 06-Jul-2023 12:11:33

279 Views

Radix sort is efficient for sorting strings because of its inherent structure of string data type.In this article, we will write a Go language program to implement radix sort for sorting strings. We start working on an unsorted array string and demonstrate how radix sort can be applied to sort it. A string is a character array or combination of characters. Syntax func make ([] type, size, capacity) The make function in Go is used to build an array/map. It receives as arguments the kind of variable to be generated, as well as its size and capacity. func range(variable) ... Read More

Golang program to implement radix sort using bucket sort as a subroutine

Akhil Sharma
Updated on 06-Jul-2023 12:09:31

147 Views

A subroutine is a part of a program which performs a specific task and can be called repeatedly based on the purpose and use. When a subroutine is called, the program shifts to that routine and executes the instructions inside that routine.Radix sort is an algorithm that sorts elements from their digits. It has a linear time complexity and is used for sorting large amounts of data. It uses counting sort to calculate the frequencies of digits.In this Golang article, we will write programs to implement radix sort using bucket sort as a subroutine. Syntax func len(v Type) int ... Read More

Advertisements