// JP opened flex table

Click to See Complete Forum and Search --> : Doubly List - Help needed


fusionplus
March 22nd, 2007, 09:03 PM
Hi.. i have a complicated doublylinkedlist that i am stuck at a position.. See, the list is distributed into boxes... each box is of certain size.. once the elements added to first box are filled, it creates the next box... for e.g.

A-b-c-d-E-f-g-h-i-J-k-l-m

The capital letters are box headers. Each box is of size 4.

the value variable tells which node.

Now, if i want to get to E box header, how can i do it.. i am using a while loop,
but the loop doesn't stop at the boxheader that has the element, it goes to the end boxheader.. here's the code...

(i have to get the value number on the linked list. First by getting to that box and then getting to that value node).

/** nextBox goes from one boxheader to next. */

BNode node = front;
BNode node2 = null;

int i = 0;
while (i < index) {
node = node.nextBox;
node2 = node;
}
for (int x = i; x < index; x++) {
node2 = node2.next;
}

System.out.println(node2.getValue());


Now suppose if the value was 5. The node2 should return "f". but instead the nextBox goes all the way to the end... PLZ help..

petes1234
March 22nd, 2007, 09:09 PM
do you mean to nest your for loop inside your while loop? Also, where in these loops are you checking your values?

fusionplus
March 22nd, 2007, 09:13 PM
ok in order to get to the *index* element in the list... i have to first jump thru boxes. Then the node2 goes thru the boxheader till the value number and return that node.

nextBox jumps from one boxheader to the next.

i have been trying for a while now.. but cannot get it to work...

dlorde
March 23rd, 2007, 06:10 AM
You're using the same index value to find the right box and to step through the contents of that box. That doesn't sound right.

Worse than that, you use a variable 'i' to count the boxes, but you never increment it, so the loop will always just run off the end.

If you step through this code by hand with pencil and paper, you'd spot this immediately.

Progress is possible only if we train ourselves to think about programs without thinking of them as pieces of executable code...
E. Dijkstra

//JP added flex table