![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Sep 2005
Posts: 7
Rep Power: 0
![]() |
Calling on All Programmers;
I have a challenging (for me) question that I really need some help to get going in the right direction. I need to code a NewList (ADT) that will implement a separate file shown below: -------------------------------------------- interface SmallList <ItemType> //Small list { public static final int MAX_LENGTH=5; public boolean insertItem (ItemType newItem); public boolean delItem(); public boolean newPos(); public ItemType getItem(); } // End of SmallList -------------------------------------------- What I have at this point is a blank page quite frankly. I need some help to implement the interface shown above. Any help, comments, direction, etc. would be much appreciated. To start: public class NewList <ItemType> implements SmallList <ItemType> { } Thanks |
|
|
|
|
|
#2 |
|
Sexy Programmer
|
When a class implements an interface, the programmer must define all the method that are in that interface. Here's a small example of a class that implements an interface.
import java.util.Stack;
import java.util.ArrayList;
public class ChrisList implements Stack
{
private ArrayList list;
public ChrisStack
{
list = new ArrayList();
}
public boolean isEmpty()
{
return list.size() == 0;
}
public void push(Object o)
{
list.add(o);
}
public Object pop()
{
return list.remove(list.size() - 1);
}
public Object pop()
{
return list.get(list.size() - 1);
}
}For your ADT, you just have to define all those methods in your class. public class NewList<ItemType> implements SmallList<ItemType>
{
public boolean insertItem(ItemType newItem)
{
//write your own implementation
}
public boolean delItem()
{
//write your own implementation
}
public boolean newPos()
{
//write your own implementation
}
public ItemType getItem();
{
//write your own implementation
}
}
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Sep 2005
Posts: 7
Rep Power: 0
![]() |
Thanks for your help. Here is a quick description of the above:
public class NewList<ItemType> implements SmallList<ItemType>
{
public NewList()
{
//Constructs a new empty list and sets m & p to 0.
//m is the length of the list and p marks the current position.
//One constructor and no parameters.
}
public boolean insertItem(ItemType newItem)
{
//If p or m = the max length in SmallList, it fails
//If success, every item i is moved to the right
//Length of list m is increased by 1
//Value of p has not changed
//Current item is newItem.
}
public boolean delItem()
{
//If m or p = 0, it fails
//If success, the item in p is deleted
//Every item i is shifted to the left by one position
//Length of list m is decreased by 1
//Current position p has not changed.
}
public boolean newPos()
{
//Is true if 1 is less than or equal to p and p is less
//than or equal to m and returns false otherwise
}
public ItemType getItem();
{
//If 1 is less than or equal to p and p is less than or equal
//to m, it returns the item in p. Otherwise it is null.
}
} |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
perhaps a "heap" data structure would fulfill your needs? if java doesn't have one, then oh well...
__________________
i put on my robe and wizard hat... Have you ever heard of Plato, Aristotle, Socrates?...Morons. |
|
|
|
|
|
#5 |
|
Sexy Programmer
|
Dude, if you can't convert your pseudocode into Java statements then I suggest you read up on Java. All you have to do is create private list object within your NewList class and just remove according to the directions given.
Also, the p value never changes. Is p the first index of your list? Why do you keep track of the position when all you do is remove an object from the front of the list? This data structure of yours does not make sense and has no point because all you are doing in reinventing the wheel.
__________________
I would love to change the world, but they won't give me the source code! |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| dev c++ software, template problem | cairo | C++ | 11 | Jun 2nd, 2006 12:42 PM |
| C# corruption!!! | Kilo | C++ | 32 | May 21st, 2006 8:44 PM |
| Help in QBASIC (I think it's similar to VB) | phoenix987 | Visual Basic | 3 | May 9th, 2005 12:33 PM |
| Help with a QBASIC program | phoenix987 | Other Programming Languages | 4 | May 5th, 2005 12:27 PM |
| airport Log program using 3D linked List : problem reading from file | gemini_shooter | C++ | 0 | Mar 2nd, 2005 4:12 PM |