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()); |