Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-15-2008, 05:44 PM
Member
 
Join Date: Feb 2008
Posts: 1
nt5515 is on a distinguished road
Event
m trying to write a program that store a binary tree of possible events in an array. i need to be able to sort the the Events in the array based on the previous event that caused it by the time which they will occur. After the specific time has passed the event will be removed and all other events will be bumped up, all the while new events will be added to the end and sorted by their time.

Please Help

heres wot i've got so far, i've got some test that will test whe the program is doin wot it should. i just dont know how to implement the add(event) and remove(event) methods

// Store a collection of events. The operations are to add an event to the
// collection, or to remove the earliest event from the collection.
// Internally, a priority heap is used to provide an efficient implementation.

class EventQueue
{
// The fields of an EventQueue are...
Event[] eventqueue = new Event[100];
// The capacity() method returns the maximum size that the queue can grow
// to without resizing.
public int capicity()
{
return eventqueue.length;
}
// The size() method returns the number of events currently in the queue.
public int size(int count)
{
for (int i=0; i<eventqueue.length;i++)
{
if (eventqueue != null);
count = count+1;
}
return count;
}
// The add(event) method adds an event to the queue.
public void add(Event event)
{


}

// The take() method returns the earliest event in the queue.

// Test the queue.

public static void main(String[] args)
{
EventQueue q = new EventQueue();
Event e1 = new Event("One", 1);
Event e2 = new Event("Two", 2);
Event e3 = new Event("Three", 3);
q.add(e2);
q.add(e3);
q.add(e1);
test(q.size(), 3, "The queue should have size 3.");
test(q.capacity() >= 3, true, "The capacity should be >= size.");
test(q.take(), e1, "The earliest event was expected.");
test(q.take(), e2, "The second event was expected.");
test(q.take(), e3, "The third event was expected.");
}

// Test that an actual value matches an expected value, either of which can
// be null. Print the given message and throw an error if not.

private static void test(Object actual, Object expected, String message)
{
if (actual == null && expected == null) return;
if (actual != null && actual.equals(expected)) return;
System.err.print(message);
System.err.print(": " + actual);
System.err.println(", not " + expected);
throw new Error("Testing failed.");
}
}
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Listener for SWT event Java Tip Java Tips 0 01-08-2008 10:04 AM
SWT Event Handling Java Tip Java Tips 0 12-30-2007 01:21 PM
key pressed event kavithas New To Java 7 12-10-2007 03:01 PM
Need help with JButton event adlb1300 New To Java 2 11-19-2007 02:15 AM
Event Handling luisarca Sun Java Wireless Toolkit 5 05-07-2007 07:05 PM


All times are GMT +3. The time now is 07:59 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org