gs gs121 Abstract Data Types - Stack using Linked List - Quiz No.1
gs gs121 Data Structures and Algorithms Quiz
This quiz belongs to book/course code gs gs121 Data Structures and Algorithms of gs organization. We have 169 quizzes available related to the book/course Data Structures and Algorithms. This quiz has a total of 10 multiple choice questions (MCQs) to prepare and belongs to topic Abstract Data Types. NVAEducation wants its users to help them learn in an easy way. For that purpose, you are free to prepare online MCQs and quizzes.
NVAEducation also facilitates users to contribute in online competitions with other students to make a challenging situation to learn in a creative way. You can create one to one, and group competition on an topic of a book/course code. Also on NVAEducation you can get certifications by passing the online quiz test.
Select from the options the appropriate pop() operation that can be included in the Stack class. Also ‘first’ is the top-of-the-stack.
class Node { protected Node next; protected Object ele; Node() { this(null,null); } Node(Object e,Node n) { ele=e; next=n; } public void setNext(Node n) { next=n; } public void setEle(Object e) { ele=e; } public Node getNext() { return next; } public Object getEle() { return ele; } } class Stack { Node first; int size=0; Stack() { first=null; } }
public Object pop() { if(size == 0) System.out.println("underflow"); else { Object o = first.getEle(); first = first.getNext(); size--; return o; } }
public Object pop() { if(size == 0) System.out.println("underflow"); else { Object o = first.getEle(); first = first.getNext().getNext(); size--; return o; } }
public Object pop() { if(size == 0) System.out.println("underflow"); else { first = first.getNext(); Object o = first.getEle(); size--; return o; } }
public Object pop() { if(size == 0) System.out.println("underflow"); else { first = first.getNext().getNext(); Object o = first.getEle(); size--; return o; } }
public Object some_func()throws emptyStackException { if(isEmpty()) throw new emptyStackException("underflow"); return first.getEle(); }
public void display() { if(size == 0) System.out.println("underflow"); else { Node current = first; while(current != null) { System.out.println(current.getEle()); current = current.getNext(); } } }
class Node { protected Node next; protected Object ele; Node() { this(null,null); } Node(Object e,Node n) { ele=e; next=n; } public void setNext(Node n) { next=n; } public void setEle(Object e) { ele=e; } public Node getNext() { return next; } public Object getEle() { return ele; } } class Stack { Node first; int size=0; Stack() { first=null; } }
public void push(Object item) { Node temp = new Node(item,first); first = temp; size++; }
public void push(Object item) { Node temp = new Node(item,first); first = temp.getNext(); size++; }
public void push(Object item) { Node temp = new Node(); first = temp.getNext(); first.setItem(item); size++; }
public void push(Object item) { Node temp = new Node(); first = temp.getNext.getNext(); first.setItem(item); size++; }