Data Structure

Quick Sort Algorithm

Question: Write a program to implement Quick Sort Algorithm. Requirements : public static void quickSort(int[] ar,int start,int end) public static int partition(int[] ar,int start,int end) Implement the main() inside the class : ‘QuickSort’ Sample Input and Output 1: How many elements?8 Enter array elements:2 1 5 3 4 8 7 6 Array after sorting:1 2 3…

String Reverse – Recursion

Question: Ram participates in an online gaming contest, where he is asked to code logic in Java to reverse the given word using recursion. Help Ram to perform the same. Check the sample input and output statements for more clarifications. Function signature should be: public static String reverseString(String str) Implement the main() inside the class ‘ReverseDriver’ Sample…

String Sorting

Question: John likes to play with string and he always tries to do something new with it. This time he found a very typical way to sort a string. What he did is that he took a string composed of both lowercase and uppercase letters and sorted it in such a manner such that the uppercase…

World Cup

Question: Some teams qualified for the 2014 World Cup. The score of the teams were stored in an array in sorted order and array index is the represents the team. Index 0 represents the Team 1; index 1 represents the Team 2 and so on. If a score is given, then should find out which…

Stack Reverse – Recursion

Question: Implement Stack using recursion and reverse the stack content. Stack should be represented using a linked list. Generate linked list in an ordered set of data elements, each containing a link to its successor. Requirements:class Node{    int value;   Node next;};int createStack(); void displayStack(); void stackReverse(); Note: Implement the main() inside the class ‘StackDriver‘ Sample Input/Output…

Linked List – Recursion

Question: Rose participates in an online gaming contest, where she is asked to code logic in Java to count the number of occurrences of a given element in a given linked list using recursion. Help Rosy to perform the task.  Check the sample input and output statements for clarifications. Note: Implement the main() inside the…

Replace Character

Question: String – Replace Characters  Write a recursive function ‘public static String replace(String str,char from,char to) ‘ that changes all occurrences of ‘from’ in ‘str’ to ‘to’. For example, if str were “codebook”, and from = ‘o’ and to = ‘e’, then, str would become “cedebeek”. Function Definitions: public static String replace(String str, char from,…

Scorecard – Queue

Question: Dan is playing a video game in which his character competes in a hurdle race by jumping over hurdles with heights. He used to maintain the maximum height of units he jumps in each race in his scorecard.  But in this score card he can only append the score one after another. He cannot…

Occurrences

Question: Given a single linked list and an integer x your task is to complete the function deleteAllOccurences which deletes all occurrences of a key x present in the linked list. The function takes two arguments: the head of the linked list and an integer x. The function should return the head of the modified linked list….

x