Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Data structure for java

Name: Anonymous 2010-05-16 5:14

Sup /prog/, I need to an indexed data structure that supports these methods:


void addLast(S stuff);     // insertion's like a queue
void removeLast();         // removes last link
void removeIfHas(S stuff); // removes link if has target stuff
S getStuff(int index);     // retrieves stuff given the index


I can do this with a (Doubly/Double) Linked List, but the search/retrieval is O(n). Is a HashTable a better structure?

Thanks

Name: Anonymous 2010-05-16 6:17

>>9
You are correct- I didn't see that addLast worked like a queue, otherwise we can just swap with the last item in the list. I'll think on it but I suspect we can at best achieve O(log n) for one of getStuff(int index) and removeIfHas, and O(1) for the other.
That being said this problem seems very arbitrary and I suspect OP has made a design mistake to get to the point where this set of operations is required in the first place.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List