Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Articles by Shubham B Vora
3 articles
Java program to find the top and bottom elements of a given stack
In this tutorial, we will be looking at how to find the top and the bottom elements in a given stack using Java. When we look at the stack, it represents a linear dataset following the Last In, First Out (LIFO) principle, hence the elements are added and removed in the same place. We will further explore two approaches for finding a given stack's top and bottom elements, i.e. via iteration and recursion. Problem Statement We will be given a stack array of n elements and the task is to find the 1st and nth element of the stack without ...
Read MoreDelete all even elements from a stack in Java
In this tutorial, we will learn to remove all even numbers from the given stack containing integer values. In Java, the stack is a data structure that works based on the Last-In-First-Out (LIFO) principle. It means, whatever elements you have added in the last, you can get it first. Removing even elements from the stack is useful in many real-world scenarios. For example, you can use this technique to filter the data from the stack. However, filtering logic can differ according to the scenario. In our case, we will remove even numbers and filter odd numbers. In other cases, you ...
Read MoreJava program to count all stack elements
In this tutorial, we will learn to count the number of elements in the stack using various approaches. In Java, a Stack is a fundamental data structure that follows the Last-In-First-Out (LIFO) principle, meaning whatever element is recently added to the stack, will be accessed first. The real-time applications of the stack are function call management, expression evaluation, etc. In such scenarios, we might need to count the number of stack elements. For example, counting the total number of function calls while using the stack for function call management and the total number of operations to be performed while evaluating ...
Read More