Author: BIM Notes
Database 2021 Makeup Solution
Q. No 4 — Find the name of teacher which from biratnagar or dharan select TNAME FROM TEACHER WHERE ADDRESS=’BIRATNAGAR’ OR ADDRESS=’DHARAN’ ; SELECT TNAME FROM TEACHER WHERE ADDRESS IN(‘BIRATNAGAR’,’DHARAN’); — Find the name of teacher who teaches database managemnet system SELECT TNAME FROM TEACHER WHERE TID IN(SELECT TID FROM TEACH WHERE SID =(SELECT SID […]
Continue ReadingDSA 2021 Old Paper solutions
Q.no 11
1 2 3 4 5 6 7 8 9 10 11 |
public void push(int element) { // Check if stack is full. if (top == (MAX_SIZE - 1)) { System.out.println("Stack Overflow"); } else { top = top + 1; stack[top] = element; System.out.println(element + " pushed into stack"); } } |
Q.no 12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
public class LinkedList { // head of list Node head; /* Linked list Node*/ class Node { int data; Node next; Node(int d) { data = d; next = null; } } /* Inserts a new Node at a specific position. */ public void insertAtPosition(int data, int position) { Node new_node = new Node(data); if (head == null) return; Node temp = head; if (position == 0) { new_node.next = head; head = new_node; return; } for (int i = 0; temp != null && i < position - 1; i++) temp = temp.next; if (temp == null || temp.next == null) return; |
Q.no 13 Q.no 14
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
public class TowerOfHanoi { public static void main(String[] args) { int numOfDisks = 3; // A, B, C are names of rods towerOfHanoi(numOfDisks, 'A', 'C', 'B'); } // Java recursive function to solve tower of hanoi puzzle static void towerOfHanoi(int n, char from_rod, char to_rod, char aux_rod) { if (n == 1) { System.out.println("Move disk 1 from rod " + from_rod + " to rod " + to_rod); return; } towerOfHanoi(n-1, from_rod, aux_rod, to_rod); System.out.println("Move disk " + n + " from rod " + from_rod + " to rod " + to_rod); towerOfHanoi(n-1, aux_rod, to_rod, from_rod); } } |
Q.no 15
Continue ReadingDSA 2022 Old Paper Solution
Group B Q.no 11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
public void deleteFromPosition(int position) { if (head == null) return; Node temp = head; if (position == 0) { head = temp.next; return; } for (int i = 0; temp != null && i < position - 1; i++) { temp = temp.next; } if (temp == null || temp.next == null) return; Node next = temp.next.next; temp.next = next; if (next != null) next.prev = temp; } |
Q.no 12
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import java.util.Scanner; import java.util.Stack; public class StackDemo { public static void main(String args[]) { Stack<Integer> st = new Stack<Integer>(); Scanner sc = new Scanner(System.in); System.out.println("Stack Test\n"); char ch; do { System.out.println("\nStack Operations"); System.out.println("1. push"); System.out.println("2. pop"); System.out.println("3. peek"); System.out.println("4. check empty"); System.out.println("5. size"); int choice = sc.nextInt(); switch (choice) { case 1 : System.out.println("Enter integer element to push"); st.push( sc.nextInt() ); break; case 2 : try { System.out.println("Popped Element = "+ st.pop()); |
Q. No 14 Q. No 15
Continue Reading