You can watch me live code the Stack Datastructure on youtube. You can get the entire source code from github I have put all the function declaration in a header file. struct Stack{ int top; int capacity; int *data; }; //Creation struct Stack *createStack(int *capacity); //Deletion int deleteStack(struct Stack *stack); //Status Checks int isStackFull(struct Stack *stack); […]
Convert infix equation to postfix in java
We know stack is first in and last out. The first to go inside a stack is going to be the last to come out of it. So, the aloglrithm to convert a infix to postfix is simple. We print all the operands. Operands are something which are not mathematical symbols and does not represent […]
Do inorder traversal on a binary tree in java.
Hello there. In this article, we will be traversing a binary tree, and we also print the data stored in those node. In the inorder traversal, we print the left child – root – right child. Here is simple recursive algorithm to do that. go to left child – print the left child print the root […]
Create a complete binary tree from an array of data in java
Note :- Using java 8 and above. Hi there… Today, I am going to write a java program which will take an var-arg of character, you can use any data-type you want. Data type is not the focus here. The main focus is the process of creating a binary tree. I am using functional programming to do […]
Class to represent a binary tree node in java.
A node in a binary tree contains data and reference to it’s left and right child. You can add as many instance variables you want, because all of them represent data. You can have multiple maps, multiple lists another class objects. Because, all of those are data. But, objects to access the left and right […]
A simple queue implementation using array in java.
Queue is a data-structure, which follows the FIFO. It means ‘First In First Out’. The element which goes first in the array should be the first to come out. To achieve this process, we add elements at one end of the array and remove it from the other end. Things that we need to do while […]
Implementing Stack Datastructure using arrays.
Stack is a way of accessing data, Last In First Out (LIFO). It has nothing to do with underlying memory structure, whether it is an array or a linked list or a tree or whatever. If you are accessing the data in LIFO fashion, then it is a stack. Stack is an abstraction, it is a concept […]
Write a utility function to create linked list from a sequence of items – using iteration and recursion
While working on linked data-structures, we have to create linked lists regularly. To ease that process, we can create a utility function, which creates linked list from given data and returns head of the new linked list. Our functions will accept a variable argument and it will return a Node. We are using Node class […]
Create a Node class using java generic – for linked list
This class can not be used in any practical scenario. Because, the data part is going to be a lot different. While learning the datastructures and algorithms, this class is going to be very useful. While working on any linked datastructures, we create a class which acts as a node. And, It has following fields. […]
Find length of a linked list using recursion
You can read about calculating length of a linked list by iterative method here. In recursion, the iterative loop or explicit loop is replaced by recursive function calls. In recursive calls, a stack is used to store values calculated during the recursion. And when stack unfolds, the recursion calls are replaced by those values. Let […]