Results 1 to 16 of 16
Thread: anyone help me
- 03-11-2011, 06:54 AM #1
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
- 03-11-2011, 08:59 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
You mean the designing (UI) or the manipulation of the solution?
- 03-11-2011, 09:08 AM #3
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
both of them..the design including code of that program...can you help me?
- 03-11-2011, 09:12 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Yes I can help you. But you must show your effort before that.
- 03-11-2011, 09:17 AM #5
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
i just find the simple code..but i don't know to visualization that code..
- 03-11-2011, 09:18 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
First of all separate the things. Do you have done any UI related stuff with Java, like Swing/SWT related.
- 03-11-2011, 09:47 AM #7
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
no i don't because i don't know the step to make it
- 03-11-2011, 09:59 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Okay fine.
Did you complete the computation part of your application? If so try to workout something about drawing shapes with Java, like circles, lines, etc.
- 03-13-2011, 08:05 AM #9
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
i don't know how
- 03-13-2011, 08:19 AM #10
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
First define what a heap exactly is: a heap is a complete binary tree such that for every node the node is larger than its children (if any). If you add a node to the heap it stays a complete binary tree but you have to 'reheap' it by bubbling the newly inserted node (see your own illustration for an example). Work from there: start with the visualization of a complete binary tree.
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
- 03-13-2011, 12:46 PM #11
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
first of all,
i know what the meaning of heap..
but to make the visualization like connect node to another i can't..because i don't know the code..
thank you sir
-
What exactly do you know?
- 03-13-2011, 01:00 PM #13
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
i have a heap code from book..the output not like the picture what i mean..just text...
this is the code what i've got..
import java.io.*;
public class HeapSortApp {
public static void main(String[] args) throws IOException
{
int size, j;
//System.out.print("Enter number of items: ");
size = getInt();
Heap theHeap = new Heap(size);
for(j=0; j<size; j++) // fill array with
{ // random nodes
int random = (int)(java.lang.Math.random()*100);
Node newNode = new Node(random);
theHeap.insertAt(j, newNode);
theHeap.incrementSize();
}
//System.out.print("Random: ");
theHeap.displayArray(); // display random array
for(j=size/2-1; j>=0; j--) // make random array into heap
theHeap.trickleDown(j);
//System.out.print("Heap: ");
theHeap.displayArray(); // display heap array
theHeap.displayHeap(); // display heap
for(j=size-1; j>=0; j--) // remove from heap and
{ // store at array end
Node biggestNode = theHeap.remove();
theHeap.insertAt(j, biggestNode);
}
//System.out.print("Sorted: ");
theHeap.displayArray(); // display sorted array
} // end main()
// -------------------------------------------------------------
public static String getString() throws IOException
{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
return s;
}
//-------------------------------------------------------------
public static int getInt() throws IOException
{
String s = getString();
return Integer.parseInt(s);
}
// -------------------------------------------------------------
} // end class HeapSortApp
public class Heap {
private Node[] heapArray;
private int maxSize; // size of array
private int currentSize; // number of items in array
// -------------------------------------------------------------
public Heap(int mx) // constructor
{
maxSize = mx;
currentSize = 0;
heapArray = new Node[maxSize];
}
// -------------------------------------------------------------
public Node remove() // delete item with max key
{ // (assumes non-empty list)
Node root = heapArray[0];
heapArray[0] = heapArray[--currentSize];
trickleDown(0);
return root;
} // end remove()
// -------------------------------------------------------------
public void trickleDown(int index)
{
int largerChild;
Node top = heapArray[index]; // save root
while(index < currentSize/2) // not on bottom row
{
int leftChild = 2*index+1;
int rightChild = leftChild+1;
// find larger child
if(rightChild < currentSize && // right ch exists?
heapArray[leftChild].getKey() <
heapArray[rightChild].getKey())
largerChild = rightChild;
else
largerChild = leftChild;
// top >= largerChild?
if(top.getKey() >= heapArray[largerChild].getKey())
break;
// shift child up
heapArray[index] = heapArray[largerChild];
index = largerChild; // go down
} // end while
heapArray[index] = top; // root to index
} // end trickleDown()
// -------------------------------------------------------------
public void displayHeap()
{
int nBlanks = 32;
int itemsPerRow = 1;
int column = 0;
int j = 0; // current item
String dots = "...............................";
System.out.println(dots+dots); // dotted top line
while(currentSize > 0) // for each heap item
{
if(column == 0) // first item in row?
for(int k=0; k<nBlanks; k++) // preceding blanks
System.out.print(' ');
// display item
System.out.print(heapArray[j].getKey());
if(++j == currentSize) // done?
break;
if(++column==itemsPerRow) // end of row?
{
nBlanks /= 2; // half the blanks
itemsPerRow *= 2; // twice the items
column = 0; // start over on
System.out.println(); // new row
}
else // next item on row
for(int k=0; k<nBlanks*2-2; k++)
System.out.print(' '); // interim blanks
} // end for
System.out.println("\n" +dots+dots); // dotted bottom line
} // end displayHeap()
// -------------------------------------------------------------
public void displayArray()
{
for(int j=0; j<maxSize; j++)
System.out.print(heapArray[j].getKey() + " ");
System.out.println("");
}
// -------------------------------------------------------------
public void insertAt(int index, Node newNode)
{
heapArray[index] = newNode;
}
// -------------------------------------------------------------
public void incrementSize()
{
currentSize++;
}
// -------------------------------------------------------------
} // end class Heap
public class Node {
private int iData;
public Node (int key) {
iData = key;
}
public int getKey() {
return iData;
}
}
what about you guys???
- 03-13-2011, 01:02 PM #14
Member
- Join Date
- Mar 2011
- Location
- Indonesia, Jakarta
- Posts
- 8
- Rep Power
- 0
Sir i wanna ask..
do you know make a node with number inside the node like picture that i want??
-
- 03-13-2011, 01:26 PM #16
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,606
- Blog Entries
- 7
- Rep Power
- 17
When people rob a bank they get a penalty; when banks rob people they get a bonus.


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks