Click to See Complete Forum and Search --> : Reverse the Link list


Karephul
July 31st, 2006, 03:09 PM
I had a singly link list, so it was hard to traverse the link list in backward
direction, so I converted that singly link list to doubly link list so that
I can traverse it in backword direction too.

problem:
- If system traverse it for me .. like by while(current -> next != NULL)
it traverse it real fast .. according to the structure of the data in Link List

struct data
{
time t;
data *next
}

where is the key "time" to take care of speed of the traversal. while traversing, I can get the time from system and for every one second say.
will increment only those lists whose time is less that what I just generated
so, I will put a hold to those "data" structs whose time is greater than what
is NOW according to the program.

algo: psydo code
struct data
{
time t; // this is integer type
data *next;
}

start
1. make diffent link lists say 10;
2. each list list node has diffeent "time" associated with it.
-- This shows that if I travers all the lists together and say I have the
list like :time 1:-: time 1.5:-:time 2.0:-: ..............
and second list like

:time 2:-: time3:-:time:-4: ...........

that means while traversing i will only get node :time2: when time1, time1.5 of the first list is passed.

Who can do this by time, say if i can get the system time .. but problem is
when I will reverse, what will happen to the time ?? so I need to fuctionalty
of FWD, REV, FWD , PAUSE at the same time .,,, taking care of TIME.

Any Idea, Psudo code will be fine too..

Thanks

kumaresh_ana
August 1st, 2006, 02:13 AM
The timer ( the time you are incrementing every second ) keeps running and the constraint to traverse a node is : time( node ) <= TIME. Then there would be no problem in traversing the list.

FWD / REV :

1. do for every list
2. ptrnode = head of currentlist;
3. if ptrnode != null and ptrnode->t < TIME advance
else next list

for PAUSE you need to stop incrementing the TIME variable.

For timer update : either you can update it after every desired operation is over or you can use some threads or timer functions to maintain the variable ( but remember to keep the variable in SYNC ).


By the way what is the aim of the problem? I did not clearly understand what you are trying to say. Also you need to define what will happen to the timer when you reverse.

Karephul
August 1st, 2006, 10:00 AM
The code you have given me, I already did the same way when
I want to move in the forward direction, as I can easily say time
is incrementing(as I am using system time for that) and for every
list if myTime <= sysTime node->next;

but, when I reverse it .. I have to do node->previous; but given
the fact the time is always increasing .. how can I move my node
in backward direction ..

Time = systime = always increasing
if(myTime <= time)
node= node->next;

to Pause:
pausedTime = Time for which i am not incrementing node

now if I again want to move fwd I will say
Time = sysTime - pausedTime
if (myTime <= time)
node = node->next;

and while I am traversing the lists I am displaying the "time" ..
now when I will reverse the list ..
"Time" is dependent on systime so will be incrementing always ..
now when I say reverse I should reverse the time the same way
it use to increment that is .. 1 sec in 1 sec. .. but

time = systime - "something to reverse but what ?? say ABC"

here systime is increasing to that means ABC should also increase in the
exponential way to accomodate reverse direction Time

so, I think .. I can have a startReverseTime = Time;

time = systime - 2*startReverseTime;
if(time >= myTime)
node = node->previous;

I will try this out and will let you know .. today itself