Obviously you need to run the task that a closet running time.

For Example

Task 1 : running time = 2 secs

Task 2: running time = 4 secs

This means I want to run the task 1 after 2 secs and task 2 after 4 second.

How I hope the question is clear to you know

On Thu, Aug 4, 2011 at 11:37 AM, mohit verma <[email protected]> wrote:

> there is nothing like "search min or max time and then call function" given
> . It can be the case: "call the functions in order of nodes or times saved
> in objects". M i wrong?
>
>
> On Thu, Aug 4, 2011 at 11:56 PM, Anand Shastri 
> <[email protected]>wrote:
>
>> You mean to say linked to maintain all time task with its corresponding
>> running time and associate function. In that case how will find the task
>> which has the closed running time.
>>
>> If you use min heap it would be easy to find the task that has closest
>> runing time in O(1) complexity.
>>
>>   On Thu, Aug 4, 2011 at 10:57 AM, mohit verma <[email protected]>wrote:
>>
>>> why are u maintaining heap? can't we use link list here?
>>>
>>>   On Thu, Aug 4, 2011 at 11:16 PM, Anand Shastri <
>>> [email protected]> wrote:
>>>
>>>>   *You have given a structure which has two member, One which stores
>>>> the
>>>> time and other stores the function pointer Your function has to call the
>>>> *
>>>> *function stored in the fuction poitner after the time given in the
>>>> structure elapses.
>>>> Design that function? *
>>>>
>>>> Approach: To design this function I would use a min Heap data structure.
>>>> Each node of a heap has
>>>>                 two parameters one is the running time and other one is
>>>> the function pointer.
>>>>
>>>> // Initialise a function pointer
>>>> typedef void (*functionToBeCalled)(int arg1, int arg2);
>>>>
>>>> // Timer structure
>>>> typedef struct timer
>>>> {
>>>>    float runingTime;   // in terms of seconds
>>>>    functionToBeCalled funcToBeCall; // function pointer
>>>> }TIMER;
>>>>
>>>> void initTimer()
>>>> {
>>>>    Initialise few nodes with running time and its corresponding function
>>>>    Initialise a MIN heap data structure
>>>> }
>>>>
>>>> void addTimer(uint32 runingTime, functionToBeCalled func)
>>>> {
>>>>      TIMER *temp;
>>>>       temp = (TIMER *)malloc(sizeof(TIMER));
>>>>       temp->runingTime = runningTime
>>>>       temp->funcToBeCall = func;
>>>>       HeapAdd(temp);
>>>>       Heapify();
>>>> }
>>>>
>>>> void scheduler()
>>>> {
>>>>             uint32 currentTime = ObtainCurrentTime();
>>>>             // Obtain the runing time of top most element of the min
>>>> Heap
>>>>             uint32 runingTime = PeakHeap();
>>>>             // if the runningTime is equal to current time then extract
>>>> the top most
>>>>             // element of the heap and execute the function associate
>>>> with it
>>>>             // Heapify the MIN heap data structure
>>>>             // Obtain the runing time of top most element of the min
>>>> heap
>>>>             // scheduler sleep for that much amount of time.
>>>>             if(runingTime == currentTime)
>>>>             {
>>>>                  TIMER * node = ExtractMinHeap();
>>>>                   CreateThread(node->func, Thread);
>>>>                   Heapify();
>>>>                   runingTime = PeakHeap();
>>>>                  sleep(runningTime);
>>>>             }
>>>>             else
>>>>             {
>>>>                // scheduler updates its sleep time
>>>>               // if runing time is not equal to current time
>>>>               sleep(runningTime);
>>>>             }
>>>>
>>>>  }
>>>>
>>>> Let me know your comments
>>>>
>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups "Algorithm Geeks" group.
>>>> To post to this group, send email to [email protected].
>>>> To unsubscribe from this group, send email to
>>>> [email protected].
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/algogeeks?hl=en.
>>>>
>>>
>>>
>>>
>>> --
>>> ........................
>>> *MOHIT VERMA*
>>>
>>> --
>>> You received this message because you are subscribed to the Google Groups
>>> "Algorithm Geeks" group.
>>> To post to this group, send email to [email protected].
>>> To unsubscribe from this group, send email to
>>> [email protected].
>>> For more options, visit this group at
>>> http://groups.google.com/group/algogeeks?hl=en.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Algorithm Geeks" group.
>> To post to this group, send email to [email protected].
>> To unsubscribe from this group, send email to
>> [email protected].
>> For more options, visit this group at
>> http://groups.google.com/group/algogeeks?hl=en.
>>
>
>
>
> --
> ........................
> *MOHIT VERMA*
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.

Reply via email to