- Information
- AI Chat
Data Structure
Operating System
Students also viewed
- India Markets AND ITS Mediators
- Array Questions important questions from the beginning of the day of the day of the
- India After THE Mughal - yut7yr
- Ans-Sol JEEMain-2023 Ph-2 11-04-2023 Morning-shift
- JEE Adv leader cbt schedule and syllabus
- An Imperial capital Vijayanagara Theme 7 (Themes In indian history part 2)
Preview text
Data Structure & Algorithms.
By Ramana Sir.
Q1 :- ArrayList.
public class Node { Object ele; Node next; public Node(Object ele,Node next) { this = ele; this = next; } public Node(Object ele) { this = ele; } } public class ArrayList { Object [] a = new Object[5]; int count = 0; public void add(Object ele) { if(count==a)increase(); a[count] = ele; count++; }
public void increase() { Object [] a1 = new Object[a + 5]; for(int i = 0;i<size();i++) { a1[i] = a[i]; } a = a1; } public int size() { return count; } public Object get(int index) { if(index<0||index>size()) throw new IndexOutOfBoundsException(); return a[index]; } public int indexOf(Object ele) { for(int i = 0;i<size();i++)if(a[i]==ele)return i; return - 1; } public void set(Object ele,int index) { if(index<0||index>size()) throw new IndexOutOfBoundsException(); a[index] = ele;
this = next; } public Node(Object ele) { this = ele; } } public class LinkedList { Node head; Node tail; int count = 0; public void insertFirst(Object ele) { Node node = new Node(ele); node = head; head = node; count++; if(tail==null)tail = head; } public int size() { return count; } public void display() { Node temp = head; while(temp!=null) {
System.out(temp + " "); temp = temp; } } public void add(Object ele) { if(count==0) { insertFirst(ele); return; } Node temp = head; while(temp!=null)temp = temp; temp = new Node(ele,null); count++; } public void inserLast(Object ele) { Node temp = head; while(temp!=null)temp = temp; Node node = new Node(ele); temp = node; tail = node; tail = null; count++; } public void insertInBetween(Object ele,int index) { Node temp = head;
temp = temp.next; count--; return ele; } public Node getAdd(int index) { Node temp = head; for(int i = 0;i<index;i++)temp = temp; return temp; } public Object removeLast() { if(count==1)return removeFirst(); Object ele = tail; Node secondLast = getAdd(size()-2); tail = secondLast; tail = null; count--; return ele; } } public class LinkedListDriver { public static void main(String[] args) { LinkedList a = new LinkedList(); a(10); a(20); a(30);
a(40); a(); a(25, 2); System.out(); a(3); a(); } }
Q3 :- Double LinkedList.
public class Node { Node pre; Object ele; Node next; public Node(Node pre, Object ele, Node next) { this = pre; this = ele; this = next; } Node(Object ele) { this = ele; } } ============================================================ public class DoubleLinkedList { Node head;
public Object get(int index) { if (index < 0 || index > size()) throw new IndexOutOfBoundsException(); Node temp = head; for (int i = 0; i < index; i++) { temp = temp; } return temp; } public Object removeLast() { if (count == 1) { return removeFirst(); } Object ele = last; Node secondLast = getAdd(size() - 2); last = secondLast; last = null; count--; return ele; } public Node getAdd(int index) { if (index < 0 || index > size()) throw new IndexOutOfBoundsException(); Node temp = head; for (int i = 0; i < index; i++) { temp = temp; }
return temp; } public void addAfter(Object after, Object ele) { Node node = new Node(ele); Node p = find(after); if (p == null) { System.out("Ele Not Found"); return; } node = p; p = node; node = p; node.next = node; count++; } public Node find(Object ele) { Node temp = head; while (temp != null) { if (temp == ele) return temp; temp = temp; } return null; } public void insertLast(Object ele) {
public Object remove(int index) { if (index < 0 || index > size()) throw new IndexOutOfBoundsException(); if (index == 0) { return removeFirst(); } if (index == size()) { return removeLast(); } Node temp = head; for (int i = 1; i < index; i++) { temp = temp; } Object ele = temp.next; temp = temp.next; temp.next = temp; count--; return ele; } public void insert(Object ele, int index) { if (index < 0 || index > size()) throw new IndexOutOfBoundsException(); if (index == 0) { insertFirst(ele); return; } if (index == size()) {
insertLast(ele); return; } Node temp = head; for (int i = 1; i < index; i++) { temp = temp; } Node node = new Node(ele); node = temp; node = temp; temp = node; node.next = node; count++; } public void add(Object ele) { if (count == 0) { insertFirst(ele); return; } Node temp = head; while (temp != null) { temp = temp; } temp = new Node(last, ele, null); last = temp; count++; }
System.out("==================="); System.out(d()); } }
Q4 :- Circular LinkedList.
public class Node { Object ele; Node next; Node(Object ele) { this = ele; } public Node(Object ele, Node next) { this = ele; this = next; } }
public class CircularLinkedList { Node head; int count = 0; Node tail; public void insert(Object ele) {
Node node = new Node(ele); if (head == null) { head = node; tail = node; count++; return; } node = head; tail = node; tail = node; count++; } public int size() { return count; } public void delete(Object ele) { if (head == null) { throw new NoSuchElementException(); } if (head == ele) { head = head; tail = head; count--; return; } Node temp = head; do {
c(20); c(30); c(40); c(50); System.out(c()); c(); System.out("-----------"); c(50); c(); System.out(c()); } }
Q5 :- Queue.
public class Node { Object ele; Node next; public Node(Object ele, Node next) { this = ele; this = next; } Node(Object ele) { this = ele; }
}
--------------------------
public class Queue { Node head; int count = 0; Node tail; public void add(Object ele) { Node node = new Node(ele); if (head == null) { head = node; tail = node; count++; return; } tail = node; tail = tail; count++; } public int size() { return count; } public boolean isEmpty() { return count == 0; }
Data Structure
Subject: Operating System
- Discover more from:
Students also viewed
- India Markets AND ITS Mediators
- Array Questions important questions from the beginning of the day of the day of the
- India After THE Mughal - yut7yr
- Ans-Sol JEEMain-2023 Ph-2 11-04-2023 Morning-shift
- JEE Adv leader cbt schedule and syllabus
- An Imperial capital Vijayanagara Theme 7 (Themes In indian history part 2)