xxxxxxxxxx
/*A data structure is a particular way of organizing
data in a computer so that it can be used effectively.
For example, we can store a list of items having the same
data-type using the array data structure.*/
xxxxxxxxxx
Here are some of the data structures in java:
Array
Linked List
Stack
Queue
Binary Tree
Binary Search Tree
Heap
Hashing
Graph
xxxxxxxxxx
import java.util.*;
public class StackExample {
public static void main(String[] args) {
Stack<Integer> stack = new Stack<>();
// Pushing elements onto the stack
stack.push(10);
stack.push(20);
stack.push(30);
// Popping elements from the stack
int poppedElement = stack.pop();
System.out.println("Popped element: " + poppedElement);
// Peeking at the top element of the stack
int topElement = stack.peek();
System.out.println("Top element: " + topElement);
// Checking if the stack is empty
boolean isEmpty = stack.isEmpty();
System.out.println("Is stack empty? " + isEmpty);
// Getting the size of the stack
int stackSize = stack.size();
System.out.println("Stack size: " + stackSize);
}
}
xxxxxxxxxx
The data structure is not any programming language like C, C++, java, etc.
It is a set of algorithms that we can use in any programming language to
structure the data in the memory. To structure the data in memory, 'n' number of
algorithms were proposed, and all these algorithms are known as Abstract data types.