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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
package folder2019; import java.util.Scanner; public class no11 { private int STACKSIZE; private Integer stack[]; no11(int STACKSIZE) { this.STACKSIZE = STACKSIZE; stack = new Integer[this.STACKSIZE]; } int TOP = -1; public void push(int data) { if (TOP == STACKSIZE - 1) { System.out.println("Stack overflow"); } else { TOP++; stack[TOP] = data; } } public int pop() { if (TOP == -1) { System.out.println("Stack underflow"); } else { System.out.println("Item deleted" + stack[TOP]); TOP--; } return 0; } } class StackUsingArray { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("enter the size of stack"); int STACKSIZE = sc.nextInt(); no11 ob = new no11(STACKSIZE); int data; System.out.println("enter a number to push"); for (int i = 0; i < STACKSIZE; i++) { data = sc.nextInt(); ob.push(data); } ob.pop(); } } |
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 37 38 39 40 41 42 43 44 45 46 |
package folder2019; import java.util.Scanner; class DCLNode{ int info; DCLNode previous; DCLNode next; DCLNode(int el){ this.info=el; this.previous=null; this.next=null; } DCLNode(int el,DCLNode next,DCLNode previous){ this.info=el; this.previous=previous; this.next=next; } } class DLList{ public DCLNode head,tail; DLList(){ head=tail=null; } public boolean isEmpty(){ return head==null && tail==null; } public void insertattail(int el){ if(isEmpty()){ head=tail=new DCLNode(el); head.previous=tail; tail.next=head; } else{ tail=new DCLNode(el,head,tail); tail.previous.next=tail; head.previous=tail; } } } public class no12 { public static void main(String args[]){ Scanner sc=new Scanner(System.in); DLList ob=new DLList(); ob.insertattail(5); ob.insertattail(6); } } |
Q.no 13
Q.no 14
1 2 3 4 5 |
KurskalAlgorith(weighted connected undirected graph) tree=null; edges=sequence of all edges of graph sorted by weight; for(i=1;i<= |E| and |tree| < |V| -1;i++) if ei from edges does not form a cycle with edges in tree add ei to tree; |
Q.no 15
The topological sorting for a directed acyclic graph is the linear ordering of vertices. For every edge U-V of a directed graph, the vertex u will come before vertex v in the ordering. Topological sorting is only possible on DAG. Eg: