Found 1082 Articles for Go Programming

Golang Program to Build Right Triangle Using Numbers

Akhil Sharma
Updated on 20-Jul-2023 15:13:05

43 Views

In this article, we will write Golang programs to build a right triangle using numbers. The numbers imply that the triangle is composed of numbers. There are many ways to perform this operations, here we have used different examples to provide a better understanding of the concept. Demonstration This demonstration explains a right angled triangle representation using numbers. Each row of this triangle is consist of number starting from 1 to the row number. From top the first row has 1, second row has 1, 2 and it goes on. 1 1 2 1 2 3 1 ... Read More

Golang Program to Count no. of Numerical Digits in a String

Akhil Sharma
Updated on 20-Jul-2023 15:02:06

468 Views

A Golang string is a sequence of characters created using quotes. Strings are immutable here, which means once created cannot be modified. Here we will work on strings to find numerical digits present in them.In this article, we will write a Go language program to count no. of numerical digits in a string. Demonstration This demonstration explains that “helloalexa234567playthesong” is an input string and it contains six numeric digits, the role of the program is to tally all the numeric digits available in the provided string. Input string − helloalexa234567playthesong Number of Numeric Digit − 6 Syntax unicode.IsDigit() ... Read More

Golang Program to Implement Slices

Akhil Sharma
Updated on 20-Jul-2023 14:58:04

109 Views

A slice in golang is a dynamic array created to add extra elements which cannot be added in an array as it has a fixed size. In this particular article, two examples are used to demonstrate the use of slices. In both of the examples, various operations are performed on the slices to show its working. In the first example, a slice of string is created and in the second example, slice of integers is created. Let’s see the operations via examples to get a crystal-clear understanding of the concept. Syntax funccopy(dst, str[] type) int The copy function in ... Read More

Golang Program to Create Slice of Slices

Akhil Sharma
Updated on 20-Jul-2023 14:55:51

114 Views

A slice in go language is a variable length array which means that values can be added and deleted from it as per convenience. In this article, we will create a slice of slices using two examples, slice of slices means that many slices are contained in a slice. In the first example, we will demonstrate the creation of slice of slices in two ways, firstly we will initiate the slice of slices with some values and in the second way an empty slice of slices will be created in which values will be appended later on. In the second ... Read More

Golang Program to Create Slice Using Composite Literal

Akhil Sharma
Updated on 20-Jul-2023 14:53:46

84 Views

In Go programming language, a composite literal is used to create a slice, array, struct etc object of type given and initializes it. In this article, we will create a slice using three examples. In the first example, slices of numbers will be created, in the second example, slices of strings will be created and in the third example, built-in functions are used to create slices. In this way the creation of slices is demonstrated. Let’s see the examples to get a crystal-clear view of the concept. Syntax func make ([] type, size, capacity) The make function in go ... Read More

Golang Program to Show Use of this Keyword in Class

Akhil Sharma
Updated on 20-Jul-2023 14:52:10

126 Views

In Go programming language, there is no concept of classes so struct are used to demonstrate the use of this keyword in class. The "this" keyword refers to the current method or object that is currently being executed in the program. In this article we will use two examples to see how the program works. In the first example, we will use Child struct by calling the method on this struct and printing its name and age whereas in the second example, we will use a Rectangle struct to print its area by calling the method on this struct. Let’s ... Read More

Golang Program to Implement a Priority Queue Using a Balanced Binary Search Tree (e.g. AVL Tree)

Akhil Sharma
Updated on 20-Jul-2023 14:51:14

127 Views

In this article, we implement a priority queue using a balanced binary search tree, specifically an AVL tree. Here we are going to use seven  different methods: PriorityQueue struct, Node struct, insert, remove, Isempty, size as well as peek along with examples to elaborate the concept. Syntax func (pq *PriorityQueue) Insert(value interface{}, priority int) The Syntax func (pq *PriorityQueue) Insert(value interface{}, priority int) is a method declaration in Golang. It defines a method named Insert that operates on a PriorityQueue instance (receiver) represented by pq. func (pq *PriorityQueue) Remove() interface{} The Syntax func (pq *PriorityQueue) Remove() interface{} is ... Read More

Golang Program to Implement a Priority Queue Using a Linked List

Akhil Sharma
Updated on 20-Jul-2023 14:45:34

131 Views

A priority queue is a data structure where each element is assigned a priority and elements with higher priority are dequeued first. In this article, The Golang program focuses to implement a priority queue using a linked list. Here we are going to use seven different methods: PriorityQueue struct, Node struct, insert, remove, Isempty, size as well as peek along with examples to elaborate the concept. Syntax type PriorityQueue struct { head *Node} The Syntax type PriorityQueue struct { ... } defines a struct type called PriorityQueue in Golang. It has one field: head of type *Node. The PriorityQueue struct ... Read More

Golang Program to Count The Possible Decodings of a Given Digit Sequence

Akhil Sharma
Updated on 20-Jul-2023 14:44:37

36 Views

A digit sequence in go language is a set of digits that is used to represent a number. We can represent the digit sequence by using go languages existing data type. In this article, the Golang program is  designed to calculate the possible decodings of a given digit sequence. It solves this problem by using dynamic programming techniques. Given a sequence of numbers, the program calculates the number of ways numbers can be determined.Here we are going to use the method countDecodings along with examples to elaborate the concept. Syntax func countDecodings(digits string) int The countDecodings function is expected ... Read More

Golang Program to Insert a Node in a Sorted Doubly Linked List

Akhil Sharma
Updated on 20-Jul-2023 14:43:44

112 Views

A doubly linked list could be an information structure where each node contains a reference to both its previous and following nodes. The program points to preserve the sorted arrangement of the linked list whereas inserting an unused node. In this article, we will learn to create a Golang program that focuses on inserting a node into a sorted doubly linked list. Here we are going to use the method insertNode along with examples to elaborate on the concept. Syntax func insertNode(head *Node, value int) *Node This Syntax represents a function named "insertNode" that takes a pointer to the ... Read More

Advertisements