Akhil Sharma

Akhil Sharma

507 Articles Published

Articles by Akhil Sharma

Page 31 of 51

Golang program to convert file to byte array

Akhil Sharma
Akhil Sharma
Updated on 21-Feb-2023 18K+ Views

In Go programming language we can use byte function and ioutil.ReadFile function to convert a file into byte array. The os package file type that offers ways to open, read from, write to, and manipulate files whereas array is a fixed-size group of identical elements that may be accessed by their respective indexes, which are integers with a zero-based basis. An array's size is predetermined at the moment of declaration and cannot be altered later on. When storing a set of data with a known number of elements, arrays in Go are handy, but they have some drawbacks, such as ...

Read More

Golang program to add elements to a linkedlist

Akhil Sharma
Akhil Sharma
Updated on 21-Feb-2023 2K+ Views

In Golang, we can use node struct and linkedlist struct to add elements to a linkedlist. A linkedlist is a data structure made up of a series of nodes, each of which includes an element and a reference to the node after it in the sequence. It is a linear data structure with pointers connecting the items, and from the first node (head) to the last node, each node can be visited (tail). As opposed to arrays, which require all elements to be shifted, linked lists just require altering the pointers of the adjacent nodes, making them helpful in situations ...

Read More

Golang program to access elements from a linked list

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 485 Views

In Go Programming language, a linked list is a data structure which contains a node that further contains two values, the data and the next, where next points to the next node in the list. We will use two methods in this program to access elements from a linked list. In the first example iteration will be used and in the second example a variable current will be used to access the elements. Method 1: Using Iteration This program builds a linked list with three members and iterates through it to access and output each element's value. The output ...

Read More

Golang program to remove elements from the linked list

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 1K+ Views

In Go, a linked list is a linear data structure with pointers connecting the items, and from the first node (head) to the last node, each node can be visited (tail). We will execute the program of removing elements from the linked list using two examples. The first example uses node struct whereas the second example uses a dummy node Method 1: Using Node Struct This code creates a Node struct that has two fields: Value and Next, which links to the next node in the list. The remove_node method removes the node with the supplied value from the list ...

Read More

Golang program to add elements at first and last position of linked list

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 373 Views

In golang, a linked list is a unique data structure in which there is a value in the node and the next pointer which points to the next node. The list's initial node is referred to as the head, while the list's last node which points to nil depicts the end of list. We will add elements at the first and last position of the linked list using two examples. In the first example node struct will be used and in the second example ListNode struct will be used. Method 1: Using Node Struct In this method, we will use ...

Read More

Golang program to implement the Queue data structure

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 2K+ Views

In this Golang program, a queue is a data structure that works on the First-In-First-Out (FIFO) principle where elements are added to the rear and removed from the front. Although Go doesn't come with a built-in queue data structure, slices, linked lists, and other data structures can be used to build one. We will use two methods to implement queue data structure using slices and linked list. Method 1: Using Slice Method The fundamental operations for a queue data structure: Enqueue, Dequeue, and IsEmpty are implemented in this implementation, which employs a slice to hold the items in the ...

Read More

Golang program to create a string object

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 582 Views

In Golang, a string cannot be modified after they have been created. A built-in type in Go, the string type can be used in a variety of ways much like any other data type. In this article, we will use three methods to create a string object. The first method involves using of double quotes and backticks, in the second method strings.Replace() function is used and in the third method, a byte function is used to execute the program. Method 1: Using double quotes and backticks Two string objects, str1 and str2, are created in this program. Backticks (') are ...

Read More

Golang program to convert vector to a list

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 1K+ Views

In Golang, a vector is referred to as an array or a slice. Slice is a dynamic array whose size can be changed whereas a linked list data structure is one type of list, where each node has a value and is pointing to the next element. We will use two examples in this program to convert vector to a list. In the very first example a built-in copy function will be used and in the second example we will iterate the slice in the reverse order to obtain the output. Method 1: Using Copy Function In this method, we ...

Read More

Golang program to call one constructor from another

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 937 Views

In Go programming language, a constructor is a specific kind of function used to initialize an object's state when it is initially formed. It is used to initialize variables and provide data for the objects. We will execute this program using two methods and we will use struct in both of these examples with anonymous struct in the second example. Let’s see through these examples to understand how the program is executed. Method 1: Using a function that returns a desired type In this method, to construct a new Child struct, the NewChildWithAge function runs the NewChildfunction, sets the age, ...

Read More

Golang Program to Check Whether the Given String is Pangram

Akhil Sharma
Akhil Sharma
Updated on 20-Feb-2023 655 Views

In this article, we will understand different golang examples to check whether a given string is pangram. A statement known as a pangram uses each letter of the alphabet at least once. A pangram is a string in the programming language Golang that contains every letter of the alphabet, regardless of case. Syntax strings.ToLower(str) Using strings in Go (golang), you can change a string's case to lowercase. The strings package's ToLower() function. 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 ...

Read More
Showing 301–310 of 507 articles
« Prev 1 29 30 31 32 33 51 Next »
Advertisements