data-structures

why is compareTo returning true when it should be false?

I'm debugging erroneous search returns from my data structures class project. This current project required us to build an ordered unrolled linked list, and run a search on the contents, then return a sublist of items from an inclusive start point to an exclusive end point. In order to do this, I have to search the internal array to fi...

Data structure for a navigational sequence

I have a Silverlight LOB application that has a page that will need to be visited 4 times before moving on to the next page. I want a data structure to hold a marker to the point in that sequence. I might render a display to show where you are like this: o---●---o---o I tried an enum, but I need to associate each point with small int ...

[C] Data structure problem

Hello. I made a structure like so: struct ponto { int x; int y; int z; }; 1) Can I initialize the int's with a default value? int var = value; doesn't seem to work, compiler says "syntax error before '=' token" or something of sorts. 2) I need to work with several of these like in a array of structures, but I only know ho...

An Efficient way of randomizing an array - Shuffle code

Hi, I was asked this question in an interview and I gave various solutions but the interviewer was not convinced. I am interested to find a solution. Please throw in your views : Q: Write an efficient data structure to implement the shuffle in an ipod. It must play all the songs, each time in different random order, the same song shou...

Graphs and version control

I have a directed graph data structure, where I am trying to implement individual version control for each vertex. This creates some interesting scenarios, and I would much appreciate any ideas that you guys have. Specifically, I am looking to resolve the default behavior of the system when encountering the stated scenarios. See the fol...

Abstract classes - syntax help

I am having a bit of a problem with abstract classes. I have a bunch of classses. In the StackAsLinkedList.h class i have a linked list of pointers to Objects as seen here LinkedList<Object*> list; The syntax is wrong and i dont know what to do. if i name it a int or char i get the same syntax error.. I am fairly new to ADT / class hi...

Algorithm for 2D grid problem?

Hello everyone, I will be honest, this is an assignment question but I just cant find a solution to it. Please remember I am not asking for the answer but simply some guidance. Problem: Design an algorithm that runs in O(n) time (linear) which can locate a single suspicious house (point) on a 2D grid. It is suspicious if it consumes eq...

Correct use of Hashtable with custom class

This piece of code generates unexpected output. Hashtable<Pair, Integer> results = new Hashtable<Pair, Integer>(); results.put(new Pair(0, 1), 2); System.out.println("[DBG] " + results.containsKey(new Pair(0, 1))); The output is [DBG] false. Why did Hashtable fail to register this element? Does it have something to do with the way I t...