Shubham B Vora

Shubham B Vora

Expert Technical Content Writer | Specializing in Technology, AI, and Programming | Helping Brands Communicate Effectively

3 Articles Published

Articles by Shubham B Vora

3 articles

Java program to find the top and bottom elements of a given stack

Shubham B Vora
Shubham B Vora
Updated on 23-Sep-2024 2K+ Views

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 More

Delete all even elements from a stack in Java

Shubham B Vora
Shubham B Vora
Updated on 23-Sep-2024 3K+ Views

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 More

Java program to count all stack elements

Shubham B Vora
Shubham B Vora
Updated on 10-Sep-2024 3K+ Views

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
Showing 1–3 of 3 articles
« Prev 1 Next »
Advertisements