Data Structure

In this article, we will discuss how we can read/write a linked list to a file in C programming language. Given below is the structure of the node of the linked list that we are going to use in our example Writing Linked List to a File We are using FILE object and fwrite() to …

Program to Reverse Queue Using Stack

In this article, we will see how to reverse a queue using a stack. Steps to Reverse Queue using Stack Pop the queue and push all the elements of the queue to stack. Pop the stack and push all the elements back to the queue. The queue is now reversed. Example, Program Output Read Reverse …

Infix to Prefix

In this article, we will discuss how to convert infix expression to prefix expression using stack. Infix Expression: Infix expressions are in form Operand Operator Operand. Example, a + b. Prefix Expression: Prefix expressions are in form Operator Operand Operand. Example, + a b. For example, Input Prefix Expression: A + ( B * C …

C/C++ Program to add a node to an ascending order linked list

Write a program to add a node to an ascending order linked list in C/C++. In simple words, we need to insert data in a sorted linked list such that the linked list remains sorted even after the insertion of a new node. Example, If the current linked list is 9 -> 12 -> 14 …

C/C++ Program to find factorial using stack

Write a program to find factorial using stack in c/c++. Example, Input: 5 Output: 120 For this tutorial, we will implement our own stack. If you are using C++ then you may use the inbuilt stack. Method 1 To calculate the factorial of a number N without a stack, we use a temporary variable and …

Program to Print all the Root to Leaf Paths in the Binary Search Tree

Given a Binary Search Tree (BST), print all paths starting from root to leaf. Example, Input Output 20 -> 10 -> 520 -> 10 -> 1520 -> 30 -> 2520 -> 30 -> 35 Algorithm The question is very simple. If you look carefully at the output of the above example, you will notice that …

Program to Reverse Stack Using Queue

Reverse Stack Using Queue. Pop stack and push all the elements to a queue. Then pop queue and push all the elements back to the stack.

Student Management System using Linked List in C

In this article, we will implement a student management system using linked list in c. Student structure First, we create a structure to store student data. Insert Function After that, we create a function insert, that will add a new node to the linked list. The insert function accepts the head of the linked list …

Singly Linked List Program in C++ using class

In this article, we will be discussing Singly Linked List Program in C++ using class. A Singly Linked List is unidirectional. Each node stores the reference to the next node. Since we are not storing the address of the previous node, we cannot traverse back, making it unidirectional. The head pointer points to the first …

Difference between Array and Linked List

The main difference between array and the linked list is that array occupies contiguous memory whereas linked list memory is scattered.