gs gs121 Application of Stacks - Towers of Hanoi - 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 7 multiple choice questions (MCQs) to prepare and belongs to topic Application of Stacks. 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.
public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { System.out.println(start + " -> " + end); } else { solve(n - 1, start, end, auxiliary); System.out.println(start + " -> " + end); solve(n - 1, auxiliary, start, end); } }
public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { System.out.println(start + " -> " + end); } else { solve(n - 1, auxiliary, start, end); System.out.println(start + " -> " + end); } }
public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { System.out.println(start + " -> " + end); } else { System.out.println(start + " -> " + end); solve(n - 1, auxiliary, start, end); } }
public void solve(int n, String start, String auxiliary, String end) { if (n == 1) { System.out.println(start + " -> " + end); } else { solve(n - 1, start, end, auxiliary); System.out.println(start + " -> " + end); } }
public static void main(String[] args) { System.out.print("Enter any string:"); Scanner in=new Scanner(System.in); String input = in.nextLine(); Stack<Character> stk = new Stack<Character>(); for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String reverse = ""; while (!stk.isEmpty()) { reverse = reverse + stk.pop(); } if (input.equals(reverse)) System.out.println("palindrome"); else System.out.println("not a palindrome"); }
public static void main(String[] args) { System.out.print("Enter any string:"); Scanner in=new Scanner(System.in); String input = in.nextLine(); Stack<Character> stk = new Stack<Character>(); for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String reverse = ""; while (!stk.isEmpty()) { reverse = reverse + stk.peek(); } if (input.equals(reverse)) System.out.println("palindrome"); else System.out.println("not a palindrome"); }
public static void main(String[] args) { System.out.print("Enter any string:"); Scanner in=new Scanner(System.in); String input = in.nextLine(); Stack<Character> stk = new Stack<Character>(); for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String reverse = ""; while (!stk.isEmpty()) { reverse = reverse + stk.pop(); stk.pop(); } if (input.equals(reverse)) System.out.println("palindrome"); else System.out.println("not a palindrome"); }
public static void main(String[] args) { System.out.print("Enter any string:"); Scanner in=new Scanner(System.in); String input = in.nextLine(); Stack<Character> stk = new Stack<Character>(); for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String reverse = ""; while (!stk.isEmpty()) { reverse = reverse + stk.pop(); stk.pop(); } if (!input.equals(reverse)) System.out.println("palindrome"); else System.out.println("not a palindrome"); }
public String reverse(String input) { for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String rev = ""; while (!stk.isEmpty()) { rev = rev + stk.peek(); } return rev; }
public String reverse(String input) { for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String rev = ""; while (!stk.isEmpty()) { rev = rev + stk.pop(); } return rev; }
public String reverse(String input) { for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String rev = ""; while (!stk.isEmpty()) { rev = rev + stk.pop(); } }
public String reverse(String input) { for (int i = 0; i < input.length(); i++) { stk.push(input.charAt(i)); } String rev = ""; while (!stk.isEmpty()) { rev = rev + stk.pop(); stk.pop(); } return rev; }