plz modify this program so that it can take input as integers and string both.....

public class heap_Sort{ public static void main(String a[]){ int i; int arr[] = {1,3,4,5,2};

System.out.println("\n Heap Sort\n---------------\n"); System.out.println("\n Unsorted Array\n\n"); for (i = 0; i < arr.length; i++) System.out.print(" "+arr[i]); for(i=arr.length; i>1; i--){ fnSortHeap(arr, i - 1); } System.out.println("\n Sorted array\n---------------\n"); for (i = 0; i < arr.length; i++) System.out.print(" "+arr[i]);

}

public static void fnSortHeap(int array[], int arr_ubound){ int i, o; int lChild, rChild, mChild, root, temp; root = (arr_ubound-1)/2;

for(o = root; o >= 0; o--){ for(i=root;i>=0;i--){ lChild = (2*i)+1; rChild = (2*i)+2; if((lChild <= arr_ubound) && (rChild <= arr_ubound)){ if(array[rChild] >= array[lChild]) mChild = rChild; else mChild = lChild; } else{ if(rChild > arr_ubound) mChild = lChild; else mChild = rChild; } if(array[i] < array[mChild]){ temp = array[i]; array[i] = array[mChild]; array[mChild] = temp; } } } temp = array[0]; array[0] = array[arr_ubound]; array[arr_ubound] = temp; return;

} }

View Answers

Related Tutorials/Questions & Answers:

heap sort in java plz modify this program so that it can take input as integers and string both..... public class heap_Sort{ public static void...("\n Heap Sort\n---------------\n"); System.out.println("\n Unsorted Array\n\n

Heap Sort in Java is used to sort integer values of an array. Like quicksort... values in heap is not 0. Example of Heap Sort in Java: public class eap...:\array\sorting>java heap_Sort Heap Sort --------------- Unsorted Array 1 3

Advertisements

Heap Sort in Java ...;Javac heap_Sort.java C:\array\sorting>java heap_Sort... are going to sort integer values of an array using heap sort. There are two types

visualization Max-Heap-sort To Whom It May Concern, Would you please give the source code of applet Max-heap sort? I want to see the visualization of Max-Heap sort. Best Regards, saeideh

Quick sort in Java is used to sort integer values of an array... in comparison to other sorting algorithms like bubble sort, insertion sort, heap... into a sorted array. ADS_TO_REPLACE_1 Example of Quick Sort in Java: public class

Java heap space I am using MyEclipse 8.6 for my web based project. The command may be... Ex: java -Xms32m -Xmx128m How can I increase java heap... options available to change Heap Size. 1 -Xms<size> set initial Java

java.lang.OutOfMemoryError: Java heap space Hi, In one of my..." java.lang.OutOfMemoryError: Java heap space How to resolve this issue? Thanks Hi... your program. Check the thread Java heap space and java.lang.OutOfMemoryError

java.lang.OutOfMemoryError: Java heap space Hi, How to resolve java.lang.OutOfMemoryError: Java heap space error. This error is coming while... java.lang.OutOfMemoryError: Java heap space where there is no more space available

Java Heap The JVM's heap stores all the objects generating by a running Java program. Java uses... on the heap at run time. Garbage collection is the mechanism of automatically freeing

java heap space & netbeans Java heap space". I'm using netbeans 5.1.1 and jdk1.5.0_07 version.. can any body say how can i know the amount of java heap space while i run...java heap space & netbeans Hey,all!! I've got a problem

elasticsearch java heap space out of memory Hi, How to set heap size in elasticsearch to overcome java heap space out of memory? Thanks Hi, Set following value in environment variables: export ES_HEAP_SIZE=10g

java heap space bpbroble In my code i use JXmapViewier to show location on map but but after some time (When code is running )It give me exception that Java heap space problem how to solve that one or why this problem occurs

using java.lang.OutOfMemoryError: Java heap space i wrote a program that reads and writes multiple files and combines them and writes them as one... and my program has this error "using java.lang.OutOfMemoryError: Java heap space

Quick Sort in Java Quick Sort in Java is used to sort elements of an array..., insertion sort, heap sort and other sorting algorithms. First it divides an array... Sort algorithm in Java works? Quick Sort algorithm works on comparison sort

Controlling Java Heap Size Memory Allocation Hi, Tell me about Controlling Java Heap Size Memory Allocation? I have to run java program from console and allocate 2GB of RAM to Java Heap Size. Thanks Hi, You can

Java insertion sort question I've got another program that I need help with. I am trying to write a Java method that accepts an array of strings, and sorts the strings using the insertion sort algorithm. Then I need to write

Insertion Sort Hello rose india java experts.If you don't mind.Can you help me.What is the code for Insertion Sort and Selection Sort that displays...: public class InsertionSort { public static void sort(String[] array) { int

Java Dictionary-Sort,Extract *I need to make an English(other language) dictionary by collecting english/other language words in a text file;then using that text file I need to sort the words collected in alphabetical order

search and sort techniques in java Hi i attened an interview recently... they asked to write all searching and sorting technique codes in java.. i... of all these searchings and sortings in java...please help... Regards, Anugnya

Merge Sort in Java is used to sort integer values of an array. There are many methods to sort Java like bubble sort, insertion sort, selection sort, etc... sorted list remaining. Example of Merge Sort in Java public class

bubble sort how to write program The bubble-sort algorithm in double... Hi friend, Bubble Sort program : public class...[] = {10,5,3,89,110,120,1,8,2,12}; System.out.println("Values Before the sort:\n

Java get Heap Size In this section, we are going to illustrates you how to obtain the heap size. The heap is the area in the memory used for memory storage during

sort java 1. A statistics company wants to keep information of families. The information of a family is the family name, the number of members and first name of each member. The families are sorted alphabetically by family name

array sort hi all, can anybody tell me how to sort an array without any in-built methods. Hi Friend, Try the following code: public class SortArrayWithoutUsingMethod{ public static void sortArray(int

Sort program to sort a list of numbers in decendimg order Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.util.*; class SortListInDescendingOrder{ public static void main(String[] args

Insertion Sort In Java .... There are more efficient algorithms such as quick sort, heap sort, or merge sort... In this example we are going to sort integer values of an array using insertion sort

HEAP table hiii, What is HEAP table? hello,ADS_TO_REPLACE_1 This type of table is stored in the memory. Speed of execution of this table is very commendable

increase the JVM's maximum heap size. Hi Friends ... How to increase the JVM's maximum heap size. Just now i am getting error like : Internal compiler error :java.lang.OutOfMemoryError give me any sugg.. Thanks

with this A program is required to ask users to rate the Java programming language... Scanner(System.in); System.out.print("Rate Java(0-10): "); int rate..."); } } } } System.out.print("Invalid! Rate Java within the range(0-10): "); rate=input.nextInt

Selection sort in Java is used to sort the unsorted values in an array... the selection sort in Java. In selection sort algorithm, first assign minimum index... Sort in Java: public class selectionSort{ public static void main(String

Merge Sort String Array in Java Hello, I am trying to implement a merge sort algorithm that sorts an array of Strings. I have seen numerous.... Note: I have a separate class for merge sort in which i pass my list and the size

How to sort ArrayList in java In this section you will learn how to sort ArrayList in java. ArrayList support dynamic array that can grow as needed. Array... which sort the Arraylist. Now here is the code to sort the ArrayList in java

Bubble Sort aka exchange sort in Java is used to sort integer values..._TO_REPLACE_1 Example of Bubble Sort in Java: public class BubbleSort { public static... Sort compares first pair of adjacent elements and put larger value at higher

Insertion Sort in Java is an algorithm that is used to sort integer values..., Insertion Sort in Java is less efficient when it comes to larger data sets... decreasing. How does Insertion Sort works in Java?ADS_TO_REPLACE_1 Assume

ArrayList doesn't have sort() method. We can use the static sort method of the Collections class It sorts the given Collection object. Example of Java Arraylist Sort import java.util.ArrayList; import

Sort last modified file time in java How to sort the last modified file time in java? import java.io.*; import java.util.*; import java.text.*; public class FileModifiedDate { public static void main(String

Selection Sort In Java ... are going to sort the values of an array using selection sort.In selection sorting.... Sort the remaining values by using same steps. Selection sort

ModuleNotFoundError: No module named 'heap' Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'heap' How to remove the ModuleNotFoundError: No module named 'heap' error

Merge Sort in Java ... to sort integer values of an array using merge sort. In merge sorting.... Then merge both parts and sort it. Then again merge the next part and sort it. Do

Quick Sort in Java ... to sort integer values of an array using quick sort. Quick sort algorithm is developed by C. A. R. Hoare. Quick sort is a comparison sort. The working

heap and stack memory hi i am jane pls explain the difference between heap memory and stack memory with example programs

complete this code (insertion sort) Your task is to develop part... to use a modi¯ed version of insertion-sort algorithm which works as follows... to sort */ Scanner sc; /* for reading user input */ String line

how to sort the result of this 2 class program in java.....???? package setget1_method; import java.util.Scanner; public class Main { { { Scanner input = new Scanner(System.in); LBook[] book = new LBook[5]; String

Ads