Professional Documents
Culture Documents
IACSD
e-DAC
1. Implementbracket opening and closing operation by
using Stack and array, e.g., case 1: inputstring
“{([])}” output“Balanced”, case 2: input“({[})]]”
output”Not Balanced”
Stack class
package char_using_stack;
package char_using_stack;
if (flag == true) {
System.out.println("\"Balanced\"");
} else {
System.out.println("\"Not balanced\"");
}
}
}
Test class
package char_using_stack;
import java.util.Scanner;
Outputs
2. Implement stack using linked list
Node class
package stcak_using_linkedlist;
public Node() {
this.info = 0;
this.next = null;
}
Stack class
package stcak_using_linkedlist;
public Stack() {
top = null;
}
StackEmptyException class
package stcak_using_linkedlist;
@SuppressWarnings("serial")
public class StackEmptyException extends Exception {
TestStack class
package stcak_using_linkedlist;
Outputs
Node class
package com.app;
public Node() {
this.info = 0;
this.next = null;
}
Queue class
package com.app;
import exception.QueueHandlingException;
public Queue() {
this.tail = null;
}
QueueHandlingException class
package exception;
@SuppressWarnings("serial")
public class QueueHandlingException extends Exception {
Test class
package tester;
import com.app.Queue;
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
Outputs
4. Find mn with the help of recursion.
Recursion class
package recursion;
import java.util.Scanner;
Outputs
5. Create a singly linked list of integers such that all
elements are inserted in ascending order.
Eg.
i/p 20, 5, 10, 30, 25
o/p 5,10, 20, 25, 30
Node Class
package com.app;
public Node() {
info=0;
next=null;
}
public int getInfo() {
return info;
}
public void setInfo(int info) {
this.info = info;
}
public Node getNext() {
return next;
}
public void setNext(Node next) {
this.next = next;
}
}
SortedLL Class
package com.app;
public SortedLL() {
head = null;
}
TestSortedLL Class
package tester;
import com.app.SortedLL;
FibonacciSeries Class
import java.util.Scanner;
Outputs
7. Consider a singly linked list. Rotate the list from k
position from the last node.
Eg.
k = 2
10, 20, 30, 40, 50
After rotation
o/p
40, 50, 10, 20, 30
Node class
package com.app;
LinkedList class
package com.app;
public LinkedList() {
this.head = null;
}
TestRotation Class
package com.app;
import java.util.Scanner;