Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 19th, 2006, 10:52 PM   #1
JavaBeginner
Newbie
 
Join Date: Sep 2005
Posts: 7
Rep Power: 0 JavaBeginner is on a distinguished road
Unhappy ADT - basic list data type

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
JavaBeginner is offline   Reply With Quote
Old Dec 19th, 2006, 11:14 PM   #2
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
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);
	}
}
The methods I have written for this class are all the method the interface declares. I have written my own version of a Stack data structure. This is basically all there is to it.

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
	}
}
If you would explain the purpose of this SmallList interface you are trying to create. I would be glad to help you out more.
__________________
I would love to change the world, but they won't give me the source code!
ReggaetonKing is offline   Reply With Quote
Old Dec 20th, 2006, 12:36 AM   #3
JavaBeginner
Newbie
 
Join Date: Sep 2005
Posts: 7
Rep Power: 0 JavaBeginner is on a distinguished road
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.
	}
}
JavaBeginner is offline   Reply With Quote
Old Dec 20th, 2006, 1:09 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
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.
bl00dninja is offline   Reply With Quote
Old Dec 20th, 2006, 1:15 AM   #5
ReggaetonKing
Sexy Programmer
 
ReggaetonKing's Avatar
 
Join Date: Nov 2005
Location: New Jersey
Posts: 891
Rep Power: 3 ReggaetonKing is on a distinguished road
Send a message via AIM to ReggaetonKing
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!
ReggaetonKing is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

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




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 8:21 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC