Linear Data structures

Pardhu Guttikonda
4 min readSep 30, 2021

commonly used linear data structures.

Photo by Markus Spiske on Unsplash

🔭Types of Data Structures:-

Data structures are divided into two categories:

  1. Linear data structures
  2. Non-linear data structures

Linear data structures:-

In linear data structures, elements are arranged in sequence one after the other.

Array:-

An array is a collection of items stored at contiguous memory locations. The idea is to store multiple items of the same type together.

from google
int[] intArray = new int[20]; 

For dynamic use of arrays, we can use ArrayList:-

ArrayList<Integer> arrli = new ArrayList<Integer>();
//EmptyArrayList
ArrayList<Integer> arrc = new ArrayList<Integer>(C);
//ArrayList with C collections
ArrayList<Integer> arrli = new ArrayList<Integer>();
//EmptyArrayList with int n capacity
//common used functions
arrli.add(5);
arrli.remove(5);
arrli.set(index,element);//replaces the element
arrli.set(index,element);//inserts the element

Stack:-

It works in the LIFO(last in first out) principle. I use to remember this structure like placing all C.D’s one by one in the holder while searching we need to take out last in C.D. (OR) Pack of tennis balls.

programiz
Stack stack = new Stack();  // can push any datatype
Stack<String> stack1 = new Stack<String>(); // only String😁
//operations
stack.push(2);// adding element 2
stack.push(3);// adding element 3
stack.pop();// returns top element and removes it---3
stack.peek();//returns top element---2
stack.search(2);//returns index of element---0

Queue:-

It works in the FIFO(First in first out) principle. I use to remember this structure using the movie tickets queue, bus…

Pardhu Guttikonda

Certified AWS Cloud Practitioner

Recommended from Medium

Lists

See more recommendations