You said : "Given a linked list of infinite length"

On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
<[email protected]> wrote:
> But suppose a random number generate a value 5 and your linked list has only
> four elements. In that case what would be the answer ???
>
>
> On Thu, Dec 27, 2012 at 4:03 PM, Prem Krishna Chettri <[email protected]>
> wrote:
>>
>> Well my algo will be Something like this
>>
>> 1> Get a Random number. Perhaps You can have the function like Randon(List
>> *head, int Randomnumber)
>>
>> 2> Use the function argument Randomnumber to loop the list.
>>             i.e. for(int count=0;count<=Randomnumber;count++ ){
>>                            head = head -> next;
>> }
>>
>> 3> print (head->value);
>>
>> 4> return ;
>>
>> Now as we are using byvalue when we return the value of head remains the
>> same old head value. So everytime we call we are traversing the same old
>> list.
>>
>>  The Random variable can be taken inside the function itself if the user
>> is not taking the random value.
>>  i.e. int Randomnumber = random();  and now the user can calll Simple
>> Random(head);
>>
>>
>>
>> On Thu, Dec 27, 2012 at 3:31 PM, naveen shukla
>> <[email protected]> wrote:
>>>
>>> random node
>>
>>
>> --
>>
>>
>
>
>
>
> --
> With Best Wishes
>
> From:
>
> Naveen Shukla
> IIIT Allahabad
> B.Tech IT 4th year
> Mob No: 07860896972
> E-mail [email protected]
>
> --
>
>

-- 


Reply via email to