Found 33676 Articles for Programming

Should we declare it as Queue or Priority Queue while using Priority Queue in Java?

Sonal Meenu Singh
Updated on 22-Feb-2023 15:37:35

251 Views

Introduction The queue is a linear data structure that follows the FIFO approach to insert and extract its data. A priority Queue is a structured Queue, where all data have some priorities for their processing. In Java, a queue or priority queue is an interface. In this tutorial, we will examine whether we should declare a queue or priority queue as a Priority Queue in Java. Queue A Queue in Java is an interface and that interface belongs to java.util package. The queue interface extends the Collection Interface and this interface has several methods. Queue uses FIFO (First In First ... Read More

Golang Program to print the home directory of the current user

Akhil Sharma
Updated on 22-Feb-2023 14:23:29

2K+ Views

The Go programming language provides various methods to obtain the home directory of the current user. This information can be useful in many applications, such as file management, system configuration, etc. In this article, we will discuss different methods to get the home directory in Go along with syntax and examples. Method 1: Using os.UserHomeDir() The os.UserHomeDir() function is part of the Go standard library and is the simplest and most efficient method to get the home directory of the current user. Here is an example that demonstrates the usage of os.UserHomeDir() Syntax func UserHomeDir() (string, error) The UserHomeDir() ... Read More

Reverse a Stack using Queue

Sonal Meenu Singh
Updated on 22-Feb-2023 12:33:50

2K+ Views

Introduction Both Queue and Stack are linear data structures and are used to store data. Stack uses the LIFO principle to insert and delete its elements. A Queue uses the FIFO principle. In this tutorial, we will learn how to reverse a stack using Queue. Reversing means the last element of the Stack comes to first place and so on. What is Stack? The stack in the data structure is inspired by the stack in real life. It uses LIFO (Last In First Out) logic, which means the element that enters last in the Stack will be removed first. In ... Read More

Golang Program to get the List of filenames matching the specified wild card pattern

Akhil Sharma
Updated on 22-Feb-2023 14:20:48

4K+ Views

One of the features of Go is the ability to search and retrieve files based on a specified pattern. In this article, we will discuss different methods to get the list of filenames that match a specified wildcard pattern in Go, and provide syntax and examples for each method. Method 1: Using the "filepath.glob" The "filepath.Glob" method is the easiest and most straightforward way to retrieve the list of filenames that match a specified wildcard pattern. The function takes a pattern as input and returns a slice of strings that match the pattern. Syntax filenames, err := filepath.Glob(pattern) The ... Read More

How to Manage Full Circular Queue Event in C++?

Sonal Meenu Singh
Updated on 22-Feb-2023 12:28:34

352 Views

Introduction Circular Queue is an improvement over a linear queue and it was introduced to address the memory wastage problem in the linear queue. A circular queue uses the FIFO principle for the insertion and removal of the elements from it. In this tutorial, we will discuss the operations of the circular queue and how to manage it. What is Circular Queue? A circular queue is another kind of queue in a data structure, whose front and rear ends are connected with each other. It is also known as Circular Buffer. Its operations are similar to the linear queue, so ... Read More

Golang Program to check if a file is directory or a file

Akhil Sharma
Updated on 22-Feb-2023 14:18:40

4K+ Views

In Go, a directory is a special type of file that holds other files and directories. A directory is used to organize files on a file system and provides a structure to the file system. Go provides several functions in the os package to work with directories, including: os.mkdir, os.remove, os.open, etc. Syntax func Stat(name string) (fi FileInfo, err error) The Stat() function is present in os package and is used to check the status of a particular directory. The function takes a string parameter name, which represents the path of the directory. It returns a FileInfo structure, fi, ... Read More

Golang Program to Count number of lines present in the file

Akhil Sharma
Updated on 22-Feb-2023 14:17:00

2K+ Views

In the Go programming language, a file is a named resource for storing data that can be read from or written to. It provides a way for the program to persist data, even after the program has finished executing. Here in this article we will discuss different methods using which we can count the number of lines in a file. Method 1: Using a user-defined function In this method, we will write a go language program to count the number of lines present in the file by using bufio, fmt and os packages. Algorithm Step 1 − First, ... Read More

How to implement size-limited Queue that holds last N elements in Java?

Sonal Meenu Singh
Updated on 22-Feb-2023 11:58:17

1K+ Views

Introduction A queue is an interface in Java. It is used to insert elements at one end and remove them from another end. It uses the FIFO principle for its processing. The queue extends the Collection framework and is defined in the Java.util interface. In this tutorial, we will understand the implementation of size limited queue in Java. What is Size Limited Queue in Java? A size-limited queue is a queue with a fixed size of N. It cannot hold elements more than its size. If you try to push more data, it will remove elements from its front ... Read More

Golang Program to Perform the postorder tree traversal

Akhil Sharma
Updated on 22-Feb-2023 14:14:39

295 Views

In Go, postorder tree traversal is a technique in which the left child is visited first, then the right child, and finally the root node is the definition of the order. This order is frequently used to carry out certain activities on a tree, including releasing memory that the tree has consumed. We will implement postorder tree traversal using two methods the first one uses slices and the second one uses stacks. Syntax func append(slice, element_1, element_2…, element_N) []T The append function is used to add values to an array slice. It takes number of arguments. The first argument ... Read More

Golang Program to Count number of leaf nodes in a tree

Akhil Sharma
Updated on 22-Feb-2023 14:02:39

485 Views

In Go programming language, a tree is a data structure in which each node has a value and zero to many nodes as children. The root node is the node without a parent, while the leaf node is the node without children. Trees can be employed for a variety of tasks, including data storage, sorting, and searching in hierarchical structures. We will use two methods to count no. of leaf nodes in a tree. In the first method TreeNode struct is used whereas queue is used in the second example to execute the program. Method 1: Using TreeNode Struct This ... Read More

Advertisements