Re: [algogeeks] Linked List question

2013-01-07 Thread Doom
Thank you for the code snippet.

What I don't understand is 

if( (double)rand() / RAND_MAX   1 / k ) 

Here, Why do we use less than inequality?

Why won't Udit's solution of just using the minimum random number work?

On Tuesday, 1 January 2013 20:57:47 UTC+5:30, Dave wrote:

 @Doom: Yes. It is necessary to go through the entire list. The code could 
 look like this:
  
 int* p = head;
 int k = 1;
 while( head )
 {
 head = head - next;
 k++;
 if( k * (double)rand()  RAND_MAX )
 p = head;
 }
  
 Dave

 On Sunday, December 30, 2012 12:40:28 PM UTC-6, Doom wrote:

 Hi Dave

 Please help me with some additional clarification regarding the 
 implementation of this algo. How do we make use of random number generator?

 And is it necessary to traverse the list until the end? 


 On Friday, 28 December 2012 19:35:07 UTC+5:30, Dave wrote:

 @Sanjeev: Set a pointer p to the first node. Traverse the list. When at 
 the kth node, set p to the kth node with probability 1/k. When you reach 
 the end of the list, return p, which will point to a random node with 
 uniform probability.
  
 Dave

 On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote:

 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to 
 traverse the linked list twice in your case.
 Please reply if i am wrong ?

 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.comwrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshukla...@gmail.com 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 
 hpre...@gmail.com
  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
  naveenshukla...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshukla...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : udit...@gmail.com
 Mobile: +91-9411656264

 --





 -- 
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshukla...@gmail.com 



-- 




Re: [algogeeks] Linked List question

2013-01-01 Thread Doom
Hi Dave

Please help me with some additional clarification regarding the 
implementation of this algo. How do we make use of random number generator?

And is it necessary to traverse the list until the end? 


On Friday, 28 December 2012 19:35:07 UTC+5:30, Dave wrote:

 @Sanjeev: Set a pointer p to the first node. Traverse the list. When at 
 the kth node, set p to the kth node with probability 1/k. When you reach 
 the end of the list, return p, which will point to a random node with 
 uniform probability.
  
 Dave

 On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote:

 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to 
 traverse the linked list twice in your case.
 Please reply if i am wrong ?

 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.com wrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshukla...@gmail.com 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 
 hpre...@gmail.com
  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
  naveenshukla...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshukla...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : udit...@gmail.com
 Mobile: +91-9411656264

 --





 -- 
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshukla...@gmail.com 



-- 




Re: [algogeeks] Linked List question

2013-01-01 Thread Dave
@Doom: Yes. It is necessary to go through the entire list. The code could 
look like this:
 
int* p = head;
int k = 1;
while( head )
{
head = head - next;
k++;
if( k * (double)rand()  RAND_MAX )
p = head;
}
 
Dave

On Sunday, December 30, 2012 12:40:28 PM UTC-6, Doom wrote:

 Hi Dave

 Please help me with some additional clarification regarding the 
 implementation of this algo. How do we make use of random number generator?

 And is it necessary to traverse the list until the end? 


 On Friday, 28 December 2012 19:35:07 UTC+5:30, Dave wrote:

 @Sanjeev: Set a pointer p to the first node. Traverse the list. When at 
 the kth node, set p to the kth node with probability 1/k. When you reach 
 the end of the list, return p, which will point to a random node with 
 uniform probability.
  
 Dave

 On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote:

 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to 
 traverse the linked list twice in your case.
 Please reply if i am wrong ?

 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.comwrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshukla...@gmail.com 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 
 hpre...@gmail.com
  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
  naveenshukla...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshukla...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : udit...@gmail.com
 Mobile: +91-9411656264

 --





 -- 
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshukla...@gmail.com 



-- 




Re: [algogeeks] Linked List question

2012-12-28 Thread Dave
@Sanjeev: Set a pointer p to the first node. Traverse the list. When at the 
kth node, set p to the kth node with probability 1/k. When you reach the 
end of the list, return p, which will point to a random node with uniform 
probability.
 
Dave

On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote:

 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to traverse 
 the linked list twice in your case.
 Please reply if i am wrong ?

 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.comjavascript:
  wrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.comjavascript: 
 wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshukla...@gmail.com javascript: 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 
 hpre...@gmail.com javascript:
  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
  naveenshukla...@gmail.com javascript: wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshukla...@gmail.com javascript:
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : udit...@gmail.com javascript:
 Mobile: +91-9411656264

 --





 -- 
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshukla...@gmail.com javascript: 


-- 




Re: [algogeeks] Linked List question

2012-12-28 Thread Udit Agarwal
@Dave: U said that the node p returned will be assigned to some kth
node with probability 1/k. then the probability for p to be assigned
to 1,2,3... nodes would be like 1/1, 1/2, 1/3, and so on.. the how is
the node p is assigned with uniform probability.

On Fri, Dec 28, 2012 at 7:35 PM, Dave dave_and_da...@juno.com wrote:
 @Sanjeev: Set a pointer p to the first node. Traverse the list. When at the
 kth node, set p to the kth node with probability 1/k. When you reach the end
 of the list, return p, which will point to a random node with uniform
 probability.

 Dave

 On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote:

 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to traverse
 the linked list twice in your case.
 Please reply if i am wrong ?

 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.com wrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshukla...@gmail.com 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
  hpre...@gmail.com

  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
  naveenshukla...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshukla...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : udit...@gmail.com
 Mobile: +91-9411656264

 --





 --
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshukla...@gmail.com

 --





-- 
Udit Agarwal
B.Tech. ( Information Technology ) , 7th Semester,
Indian Institute of Information Technology
Allahabad - 211012, India
Email : uditii...@gmail.com
Mobile: +91-9411656264

-- 




Re: [algogeeks] Linked List question

2012-12-28 Thread Dave
@Udit: Here is the proof: At step k, node k is selected with probability 
1/k. On the (k+1)st step, node k is replaced with probability 1/(k+1). Thus 
it is retained with probability 1 - 1/(k+1) = k/(k+1). On subsequent steps, 
node k is retained with probabilities (k+1)/(k+2), (k+2)/(k+3), ..., 
(n-1)/n. Thus, node k is selected on the kth step and then retained until 
the end of the list with probability 1/k * k/(k+1) * (k+1)/(k+2) * ... * 
(n-1) / n. Each denominator cancels with the succeeding numerator, so the 
product collapses to 1/n.
 
Dave

On Friday, December 28, 2012 10:46:17 AM UTC-6, Udit Agarwal wrote:

 @Dave: U said that the node p returned will be assigned to some kth 
 node with probability 1/k. then the probability for p to be assigned 
 to 1,2,3... nodes would be like 1/1, 1/2, 1/3, and so on.. the how is 
 the node p is assigned with uniform probability. 

 On Fri, Dec 28, 2012 at 7:35 PM, Dave dave_an...@juno.com javascript: 
 wrote: 
  @Sanjeev: Set a pointer p to the first node. Traverse the list. When at 
 the 
  kth node, set p to the kth node with probability 1/k. When you reach the 
 end 
  of the list, return p, which will point to a random node with uniform 
  probability. 
  
  Dave 
  
  On Thursday, December 27, 2012 11:18:20 PM UTC-6, Sanjeev wrote: 
  
  i mean the length of the linked list is not known to us. 
  @udit how can we do this in single traversal ? i think we need to 
 traverse 
  the linked list twice in your case. 
  Please reply if i am wrong ? 
  
  On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal udit...@gmail.com 
 wrote: 
  
  If the length of the linked is infinite then the above algo would do 
  the needful. 
  In case you have a finite length linked list, then you can normalize 
  the random value using following: 
  Suppose length of linked list is: l 
  random number is: r; and r  l 
  then new random number would be: r1 = r%l; 
  now again use the above algo using new random number r1; 
  
  On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineet...@gmail.com wrote: 
   You said : Given a linked list of infinite length 
   
   On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla 
   naveenshukla...@gmail.com 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 
   hpre...@gmail.com 
  
   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 
   naveenshukla...@gmail.com wrote: 
   
   random node 
   
   
   -- 
   
   
   
   
   
   
   -- 
   With Best Wishes 
   
   From: 
   
   Naveen Shukla 
   IIIT Allahabad 
   B.Tech IT 4th year 
   Mob No: 07860896972 
   E-mail naveenshukla...@gmail.com 
   
   -- 
   
   
   
   -- 
   
   
  
  
  
  -- 
  Udit Agarwal 
  B.Tech. ( Information Technology ) , 7th Semester, 
  Indian Institute of Information Technology 
  Allahabad - 211012, India 
  Email : udit...@gmail.com 
  Mobile: +91-9411656264 
  
  -- 
  
  
  
  
  
  -- 
  With Best Wishes 
  
  From: 
  
  Naveen Shukla 
  IIIT Allahabad 
  B.Tech IT 4th year 
  Mob No: 07860896972 
  E-mail naveenshukla...@gmail.com 
  
  -- 
  
  



 -- 
 Udit Agarwal 
 B.Tech. ( Information Technology ) , 7th Semester, 
 Indian Institute of Information Technology 
 Allahabad - 211012, India 
 Email : udit...@gmail.com javascript: 
 Mobile: +91-9411656264 


-- 




[algogeeks] Linked List question

2012-12-27 Thread naveen shukla
Given a linked list of infinite length. Write a function to return a random
node.

Constraints:

1 You can traverse a singly linked list only once.
2 You can not use any extra space.

Thanks in advance.

-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread Prem Krishna Chettri
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 
naveenshuklasweetdrea...@gmail.com wrote:

 random node

-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread naveen shukla
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 hprem...@gmail.comwrote:

 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 
 naveenshuklasweetdrea...@gmail.com wrote:

 random node


  --






-- 
With Best Wishes

From:

Naveen Shukla
IIIT Allahabad
B.Tech IT 4th year
Mob No: 07860896972
E-mail naveenshuklasweetdrea...@gmail.com

-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread Prem Krishna Chettri
Those are the Cornor Test Cases.. Well we here talk about Algos and
Complexity (Atmost Pseudo code ) not about unit test cases and source
code.. :)

Ofcourse U can include those checks  either when U call the function or
inside the functions..

On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla 
naveenshuklasweetdrea...@gmail.com 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 
 hprem...@gmail.comwrote:

 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 
 naveenshuklasweetdrea...@gmail.com wrote:

 random node


  --






 --
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshuklasweetdrea...@gmail.com

 --




-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread Vineeth
You said : Given a linked list of infinite length

On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
naveenshuklasweetdrea...@gmail.com 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 hprem...@gmail.com
 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
 naveenshuklasweetdrea...@gmail.com wrote:

 random node


 --






 --
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshuklasweetdrea...@gmail.com

 --



-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread Udit Agarwal
If the length of the linked is infinite then the above algo would do
the needful.
In case you have a finite length linked list, then you can normalize
the random value using following:
Suppose length of linked list is: l
random number is: r; and r  l
then new random number would be: r1 = r%l;
now again use the above algo using new random number r1;

On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineeth.n...@gmail.com wrote:
 You said : Given a linked list of infinite length

 On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
 naveenshuklasweetdrea...@gmail.com 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 hprem...@gmail.com
 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
 naveenshuklasweetdrea...@gmail.com wrote:

 random node


 --






 --
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshuklasweetdrea...@gmail.com

 --



 --





-- 
Udit Agarwal
B.Tech. ( Information Technology ) , 7th Semester,
Indian Institute of Information Technology
Allahabad - 211012, India
Email : uditii...@gmail.com
Mobile: +91-9411656264

-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread naveen shukla
i mean the length of the linked list is not known to us.
@udit how can we do this in single traversal ? i think we need to traverse
the linked list twice in your case.
Please reply if i am wrong ?

On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal uditii...@gmail.com wrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineeth.n...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshuklasweetdrea...@gmail.com 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 
 hprem...@gmail.com
  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
  naveenshuklasweetdrea...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshuklasweetdrea...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : uditii...@gmail.com
 Mobile: +91-9411656264

 --





-- 
With Best Wishes

From:

Naveen Shukla
IIIT Allahabad
B.Tech IT 4th year
Mob No: 07860896972
E-mail naveenshuklasweetdrea...@gmail.com

-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread Udit Agarwal
no.. i din't know that in ur case infinite number of nodes means
unknown number of the finite nodes. I thought it to be like we have as
much number of node as we want.
and as u said if the length is know to be 4 and random number is 5
then for that i gave my approach like u can now generate a new number
as 5%4 = 1.
For case u don't know the number of nodes in the linked list (which is
finite), then we can use following approach:
For each node in the linked list, generate a random number and as u
traverse it keep track of the node address which is allotted minimum
random number and then finally return that node's address as the ans.
As each of the node is equally probable to be allotted the minimum
random number so the final answer that we have will be completely
random.
Please reply in case u still have some doubt.
Thanks

On Fri, Dec 28, 2012 at 10:48 AM, naveen shukla
naveenshuklasweetdrea...@gmail.com wrote:
 i mean the length of the linked list is not known to us.
 @udit how can we do this in single traversal ? i think we need to traverse
 the linked list twice in your case.
 Please reply if i am wrong ?


 On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal uditii...@gmail.com wrote:

 If the length of the linked is infinite then the above algo would do
 the needful.
 In case you have a finite length linked list, then you can normalize
 the random value using following:
 Suppose length of linked list is: l
 random number is: r; and r  l
 then new random number would be: r1 = r%l;
 now again use the above algo using new random number r1;

 On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineeth.n...@gmail.com wrote:
  You said : Given a linked list of infinite length
 
  On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
  naveenshuklasweetdrea...@gmail.com 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
  hprem...@gmail.com
  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
  naveenshuklasweetdrea...@gmail.com wrote:
 
  random node
 
 
  --
 
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshuklasweetdrea...@gmail.com
 
  --
 
 
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : uditii...@gmail.com
 Mobile: +91-9411656264

 --





 --
 With Best Wishes

 From:

 Naveen Shukla
 IIIT Allahabad
 B.Tech IT 4th year
 Mob No: 07860896972
 E-mail naveenshuklasweetdrea...@gmail.com

 --





-- 
Udit Agarwal
B.Tech. ( Information Technology ) , 7th Semester,
Indian Institute of Information Technology
Allahabad - 211012, India
Email : uditii...@gmail.com
Mobile: +91-9411656264

-- 




Re: [algogeeks] Linked List question

2012-12-27 Thread naveen shukla
thanks udit :) i think this approach will surely work.

On Fri, Dec 28, 2012 at 1:19 PM, Udit Agarwal uditii...@gmail.com wrote:

 no.. i din't know that in ur case infinite number of nodes means
 unknown number of the finite nodes. I thought it to be like we have as
 much number of node as we want.
 and as u said if the length is know to be 4 and random number is 5
 then for that i gave my approach like u can now generate a new number
 as 5%4 = 1.
 For case u don't know the number of nodes in the linked list (which is
 finite), then we can use following approach:
 For each node in the linked list, generate a random number and as u
 traverse it keep track of the node address which is allotted minimum
 random number and then finally return that node's address as the ans.
 As each of the node is equally probable to be allotted the minimum
 random number so the final answer that we have will be completely
 random.
 Please reply in case u still have some doubt.
 Thanks

 On Fri, Dec 28, 2012 at 10:48 AM, naveen shukla
 naveenshuklasweetdrea...@gmail.com wrote:
  i mean the length of the linked list is not known to us.
  @udit how can we do this in single traversal ? i think we need to
 traverse
  the linked list twice in your case.
  Please reply if i am wrong ?
 
 
  On Thu, Dec 27, 2012 at 10:48 PM, Udit Agarwal uditii...@gmail.com
 wrote:
 
  If the length of the linked is infinite then the above algo would do
  the needful.
  In case you have a finite length linked list, then you can normalize
  the random value using following:
  Suppose length of linked list is: l
  random number is: r; and r  l
  then new random number would be: r1 = r%l;
  now again use the above algo using new random number r1;
 
  On Thu, Dec 27, 2012 at 4:12 PM, Vineeth vineeth.n...@gmail.com
 wrote:
   You said : Given a linked list of infinite length
  
   On Thu, Dec 27, 2012 at 4:06 PM, naveen shukla
   naveenshuklasweetdrea...@gmail.com 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
   hprem...@gmail.com
   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
   naveenshuklasweetdrea...@gmail.com wrote:
  
   random node
  
  
   --
  
  
  
  
  
  
   --
   With Best Wishes
  
   From:
  
   Naveen Shukla
   IIIT Allahabad
   B.Tech IT 4th year
   Mob No: 07860896972
   E-mail naveenshuklasweetdrea...@gmail.com
  
   --
  
  
  
   --
  
  
 
 
 
  --
  Udit Agarwal
  B.Tech. ( Information Technology ) , 7th Semester,
  Indian Institute of Information Technology
  Allahabad - 211012, India
  Email : uditii...@gmail.com
  Mobile: +91-9411656264
 
  --
 
 
 
 
 
  --
  With Best Wishes
 
  From:
 
  Naveen Shukla
  IIIT Allahabad
  B.Tech IT 4th year
  Mob No: 07860896972
  E-mail naveenshuklasweetdrea...@gmail.com
 
  --
 
 



 --
 Udit Agarwal
 B.Tech. ( Information Technology ) , 7th Semester,
 Indian Institute of Information Technology
 Allahabad - 211012, India
 Email : uditii...@gmail.com
 Mobile: +91-9411656264

 --





-- 
With Best Wishes

From:

Naveen Shukla
IIIT Allahabad
B.Tech IT 4th year
Mob No: 07860896972
E-mail naveenshuklasweetdrea...@gmail.com

-- 




[algogeeks] LINKED LIST QUESTION

2012-06-04 Thread VIHARRI
Hi we need find a node in linked list in O(logn). You can change the list 
as u like.

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST QUESTION

2012-06-04 Thread Amol Sharma
not possible i suppose..
--


Amol Sharma
Third Year Student
Computer Science and Engineering
MNNIT Allahabad
http://gplus.to/amolsharma99
http://twitter.com/amolsharma99http://in.linkedin.com/pub/amol-sharma/21/79b/507http://www.simplyamol.blogspot.com/






On Mon, Jun 4, 2012 at 3:00 PM, VIHARRI viharri@gmail.com wrote:

 Hi we need find a node in linked list in O(logn). You can change the list
 as u like.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST QUESTION

2012-06-04 Thread Jeevitesh
This is possible only if Linked List is sorted then we can apply Merge Sort
for Linked List which would be in place.

Otherwise the time complexity would be O(n logn).

On Mon, Jun 4, 2012 at 3:00 PM, VIHARRI viharri@gmail.com wrote:

 Hi we need find a node in linked list in O(logn). You can change the list
 as u like.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
*Thanks,
Jeevitesh Shekhar Singh.*

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



Re: [algogeeks] LINKED LIST QUESTION

2012-06-04 Thread SANDEEP CHUGH
can be done using skip lists


On Mon, Jun 4, 2012 at 3:03 PM, Jeevitesh jeeviteshshekha...@gmail.comwrote:

 This is possible only if Linked List is sorted then we can apply Merge
 Sort for Linked List which would be in place.

 Otherwise the time complexity would be O(n logn).

 On Mon, Jun 4, 2012 at 3:00 PM, VIHARRI viharri@gmail.com wrote:

 Hi we need find a node in linked list in O(logn). You can change the list
 as u like.

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST QUESTION

2012-06-04 Thread atul anand
as question says you can change the list as u like...i guess skip list is
the answer.

On Mon, Jun 4, 2012 at 3:51 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:

 can be done using skip lists


 On Mon, Jun 4, 2012 at 3:03 PM, Jeevitesh jeeviteshshekha...@gmail.comwrote:

 This is possible only if Linked List is sorted then we can apply Merge
 Sort for Linked List which would be in place.

 Otherwise the time complexity would be O(n logn).

 On Mon, Jun 4, 2012 at 3:00 PM, VIHARRI viharri@gmail.com wrote:

 Hi we need find a node in linked list in O(logn). You can change the
 list as u like.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST QUESTION

2012-06-04 Thread Nishant Pandey
Hi ,

I think the only possiblity is to make it doubly linked list and then
consider next  prev as left and right child like tree and then perform
search as we in tree , it would serve the purpose .
let me know if iam wrong .

On Mon, Jun 4, 2012 at 3:51 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:

 can be done using skip lists


 On Mon, Jun 4, 2012 at 3:03 PM, Jeevitesh jeeviteshshekha...@gmail.comwrote:

 This is possible only if Linked List is sorted then we can apply Merge
 Sort for Linked List which would be in place.

 Otherwise the time complexity would be O(n logn).

 On Mon, Jun 4, 2012 at 3:00 PM, VIHARRI viharri@gmail.com wrote:

 Hi we need find a node in linked list in O(logn). You can change the
 list as u like.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

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



Re: [algogeeks] LINKED LIST QUESTION

2012-06-04 Thread atul anand
well converting single linked list to balanced BST...this would also work

On Mon, Jun 4, 2012 at 4:29 PM, Nishant Pandey nishant.bits.me...@gmail.com
 wrote:

 Hi ,

 I think the only possiblity is to make it doubly linked list and then
 consider next  prev as left and right child like tree and then perform
 search as we in tree , it would serve the purpose .
 let me know if iam wrong .

 On Mon, Jun 4, 2012 at 3:51 PM, SANDEEP CHUGH sandeep.aa...@gmail.comwrote:

 can be done using skip lists


 On Mon, Jun 4, 2012 at 3:03 PM, Jeevitesh 
 jeeviteshshekha...@gmail.comwrote:

 This is possible only if Linked List is sorted then we can apply Merge
 Sort for Linked List which would be in place.

 Otherwise the time complexity would be O(n logn).

 On Mon, Jun 4, 2012 at 3:00 PM, VIHARRI viharri@gmail.com wrote:

 Hi we need find a node in linked list in O(logn). You can change the
 list as u like.

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/vSoEXlaRTEIJ.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 *Thanks,
 Jeevitesh Shekhar Singh.*


  --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Cheers,

 Nishant Pandey |Specialist Tools Development  |  
 npan...@google.comgvib...@google.com |
 +91-9911258345


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked list using void pointer

2012-05-31 Thread Hassan Monfared
Why don't you use templates ?

template class T
class LNode
{
public:
LNode(T pData,LNode *pNext):data(pData),next(pNext){}
T data;
LNode *next;
};
template class T
class LList
{
protected:
LNodeT *head;
LNodeT *tail;
public:
LList()
{
head=tail=NULL;
}

void push_back(T pData)
{
if(head==NULL)
{
head=tail=new LNodeT(pData,NULL);
return;
}
tail-next=new LNodeT(pData,NULL);
tail=tail-next;
}
void push_front(T pData)
{
if(head==NULL)
{
head=tail=new LNodeT(pData,NULL);
return;
}
LNodeT *nnode=new LNodeT(pData,head);
head=nnode;
}
void Print()
{
LNodeint *cur=head;
while(cur)
{
coutcur-data',';
cur=cur-next;
}
cout  endl;
}
void Reverse()
{
LNodeT *cur=head;
LNodeT *prev=NULL;
LNodeT *tmp;
while(cur)
{
tmp=cur-next;
cur-next=prev;
prev=cur;
cur=tmp;
}
tmp=head;
head=prev;
tail=tmp;
}
};

Regards

On Thu, May 31, 2012 at 8:49 AM, mahendra sengar sengar.m...@gmail.comwrote:

 how to implement generioc linked list..using void pointer...i havent
 used void pointer much so, m not able to use it properly in linked
 list..please help asap !!!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked list using void pointer

2012-05-31 Thread Nishant Pandey
this way u can do it in c  creation and printing of generic lisk list .

void(List **p,void *data, unsigned int n)
{
List *temp;
int i;

/* Error check is ignored */
temp = malloc(sizeof(List));
temp-data = malloc(n);
for (i = 0; i  n; i++)
*(char *)(temp-data + i) = *(char *)(data + i);
temp-next = *p;
*p = temp;
}

void(List *p,void (*f)(void*))
{
while (p)
{
(*f)(p-data);
p = p-next;
}
}


void printstr(void *str)
{
printf( \%s\, (char *)str);

}

Regads
Nishant Pandey

On Thu, May 31, 2012 at 1:15 PM, Hassan Monfared hmonfa...@gmail.comwrote:

 Why don't you use templates ?
 
 template class T
 class LNode
 {
 public:
 LNode(T pData,LNode *pNext):data(pData),next(pNext){}
  T data;
 LNode *next;
 };
 template class T
 class LList
 {
 protected:
 LNodeT *head;
 LNodeT *tail;
 public:
 LList()
 {
 head=tail=NULL;
  }

 void push_back(T pData)
 {
  if(head==NULL)
 {
 head=tail=new LNodeT(pData,NULL);
  return;
 }
 tail-next=new LNodeT(pData,NULL);
  tail=tail-next;
 }
 void push_front(T pData)
  {
 if(head==NULL)
 {
  head=tail=new LNodeT(pData,NULL);
 return;
 }
  LNodeT *nnode=new LNodeT(pData,head);
 head=nnode;
 }
  void Print()
 {
 LNodeint *cur=head;
  while(cur)
 {
 coutcur-data',';
  cur=cur-next;
 }
 cout  endl;
  }
 void Reverse()
 {
  LNodeT *cur=head;
 LNodeT *prev=NULL;
 LNodeT *tmp;
  while(cur)
 {
 tmp=cur-next;
  cur-next=prev;
 prev=cur;
 cur=tmp;
  }
 tmp=head;
 head=prev;
  tail=tmp;
 }
 };

 Regards

 On Thu, May 31, 2012 at 8:49 AM, mahendra sengar sengar.m...@gmail.comwrote:

 how to implement generioc linked list..using void pointer...i havent
 used void pointer much so, m not able to use it properly in linked
 list..please help asap !!!

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

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



Re: [algogeeks] Linked list using void pointer

2012-05-31 Thread Nishant Pandey
in case of generic link list when u have to create the node u have to copy
the data part character by character ie always one -one byte and in this
way whatever be the data type of ur data u can easily get the data and
u will keep  doing this until the size of the data that to entered .

On Thu, May 31, 2012 at 9:49 AM, mahendra sengar sengar.m...@gmail.comwrote:

 how to implement generioc linked list..using void pointer...i havent
 used void pointer much so, m not able to use it properly in linked
 list..please help asap !!!

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




-- 
Cheers,

Nishant Pandey |Specialist Tools Development  |
npan...@google.comgvib...@google.com |
+91-9911258345

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



[algogeeks] Linked list using void pointer

2012-05-30 Thread mahendra sengar
how to implement generioc linked list..using void pointer...i havent
used void pointer much so, m not able to use it properly in linked
list..please help asap !!!

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



[algogeeks] Linked list MS Q

2012-01-14 Thread Ashish Goel
design a linked list that has only one pointer per node yet can be
traversed in forward or reverse direction.


Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652

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



Re: [algogeeks] Linked list MS Q

2012-01-14 Thread Ankur Garg
XOR Linked Lists

On Sat, Jan 14, 2012 at 7:06 PM, Ashish Goel ashg...@gmail.com wrote:

 design a linked list that has only one pointer per node yet can be
 traversed in forward or reverse direction.


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked list MS Q

2012-01-14 Thread atul anand
yup XOR link list

On Sat, Jan 14, 2012 at 7:13 PM, Ankur Garg ankurga...@gmail.com wrote:

 XOR Linked Lists


 On Sat, Jan 14, 2012 at 7:06 PM, Ashish Goel ashg...@gmail.com wrote:

 design a linked list that has only one pointer per node yet can be
 traversed in forward or reverse direction.


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked list MS Q

2012-01-14 Thread payal gupta
XOR linked lists...
dis willbe

On Sat, Jan 14, 2012 at 7:13 PM, Ankur Garg ankurga...@gmail.com wrote:

 XOR Linked Lists
 helpful if not known..

http://www.geeksforgeeks.org/archives/12367

Regards,
PAYAL GUPTA,
NIT-BHOPAL.


 On Sat, Jan 14, 2012 at 7:06 PM, Ashish Goel ashg...@gmail.com wrote:

 design a linked list that has only one pointer per node yet can be
 traversed in forward or reverse direction.


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked list MS Q

2012-01-14 Thread payal gupta
sorry 4 d error in last post..
dis link vud b helpful..if not known previously...

http://www.geeksforgeeks.org/archives/12367

Regards,
PAYAL GUPTA,
NIT-BHOPAL.

On Sat, Jan 14, 2012 at 7:29 PM, payal gupta gpt.pa...@gmail.com wrote:

 XOR linked lists...
 dis willbe

 On Sat, Jan 14, 2012 at 7:13 PM, Ankur Garg ankurga...@gmail.com wrote:

 XOR Linked Lists
 helpful if not known..

 http://www.geeksforgeeks.org/archives/12367

 Regards,
 PAYAL GUPTA,
 NIT-BHOPAL.


 On Sat, Jan 14, 2012 at 7:06 PM, Ashish Goel ashg...@gmail.com wrote:

 design a linked list that has only one pointer per node yet can be
 traversed in forward or reverse direction.


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST

2011-12-26 Thread Moheed Moheed Ahmad
http://cslibrary.stanford.edu/105/LinkedListProblems.pdf

-Moheed



On Sun, Dec 25, 2011 at 11:39 PM, atul anand atul.87fri...@gmail.comwrote:

 @ashish : please provide link for that page

 On Sun, Dec 25, 2011 at 10:36 PM, Ashish Goel ashg...@gmail.com wrote:

 refer stanford page
 1,2,3,4,5,6

 will become

 5,3,1
 6,4,2

 void MoveNode(struct node** destRef, struct node** sourceRef) {
 struct node* newNode = *sourceRef; // the front source node
 assert(newNode != NULL);
 *sourceRef = newNode-next; // Advance the source pointer
 newNode-next = *destRef; // Link the old dest off the new node
 *destRef = newNode; // Move dest to point to the new node
 }

 void AlternatingSplit(struct node* source,
 struct node** aRef, struct node** bRef) {
 struct node* a = NULL; // Split the nodes to these 'a' and 'b' lists
 struct node* b = NULL;
 struct node* current = source;
 while (current != NULL) {
 MoveNode(a, current); // Move a node to 'a'
 if (current != NULL) {
 MoveNode(b, current); // Move a node to 'b'
 }
 }
 *aRef = a;
 *bRef = b;
 }


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652



 On Sat, Dec 24, 2011 at 11:37 PM, atul anand atul.87fri...@gmail.comwrote:

 because you are doing odd=odd-next; and even=even-next;
 you will lose head pointers for the two linked list formed once you come
 out of the loop.



 void segregate(node* head)
 {
 node *temp,*odd,*even;
 toggle=1;
 if(head==NULL)
 {
  return;
 }
 odd=head;

 if(head-next==NULL)
 {

  return;
 }
 even=head-next;

 if(even-next==NULL)
 {
   return;
 }
 else
 {
   temp=even-next;
 }
 node *otemp,*etemp;
 otemp=odd;
 etemp=even;

 while(temp!=NULL)
 {

 if( toggle == 1)
 {

   otemp-next=temp;
   otemp=otemp-next;

   temp=temp-next;
   otemp-next=NULL;

   toggle=0;
 }
 else
 {
   etemp-next=temp;
   etemp=etemp-next;

   temp=temp-next;
   etemp-next=NULL;

   toggle=1;

 }



 }


 }

 On Sat, Dec 24, 2011 at 10:56 PM, Karthikeyan V.B 
 kartmu...@gmail.comwrote:

 Segregate even and odd psoitioned nodes in a linked list

 Eg:
 2-3-1-9-7-5
 The output should be two separate lists
 2-1-7
 3-9-5

 *My code is:*
 void segregate(node* head)
 {
 int i=1;
 node* sec=head-next;
 node *odd=head,*even=head-next;
 while(even)
 {
 if(i%2)
 {
 odd-next=even-next;
 even-next=NULL;
 odd=odd-next;
 if(!odd-next) break;
 }
 else
 {
 even-next=odd-next;
 odd-next=NULL;
 even=even-next;
 if(!even-next) break;
 }
 i++;
 }
 }

 Pls correct me if i'm wrong or suggest me a better approach

 Regards,
 KARTHIKEYAN.V.B
 PSGTECH
 CBE

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST

2011-12-25 Thread Ashish Goel
refer stanford page
1,2,3,4,5,6

will become

5,3,1
6,4,2

void MoveNode(struct node** destRef, struct node** sourceRef) {
struct node* newNode = *sourceRef; // the front source node
assert(newNode != NULL);
*sourceRef = newNode-next; // Advance the source pointer
newNode-next = *destRef; // Link the old dest off the new node
*destRef = newNode; // Move dest to point to the new node
}

void AlternatingSplit(struct node* source,
struct node** aRef, struct node** bRef) {
struct node* a = NULL; // Split the nodes to these 'a' and 'b' lists
struct node* b = NULL;
struct node* current = source;
while (current != NULL) {
MoveNode(a, current); // Move a node to 'a'
if (current != NULL) {
MoveNode(b, current); // Move a node to 'b'
}
}
*aRef = a;
*bRef = b;
}


Best Regards
Ashish Goel
Think positive and find fuel in failure
+919985813081
+919966006652


On Sat, Dec 24, 2011 at 11:37 PM, atul anand atul.87fri...@gmail.comwrote:

 because you are doing odd=odd-next; and even=even-next;
 you will lose head pointers for the two linked list formed once you come
 out of the loop.



 void segregate(node* head)
 {
 node *temp,*odd,*even;
 toggle=1;
 if(head==NULL)
 {
  return;
 }
 odd=head;

 if(head-next==NULL)
 {

  return;
 }
 even=head-next;

 if(even-next==NULL)
 {
   return;
 }
 else
 {
   temp=even-next;
 }
 node *otemp,*etemp;
 otemp=odd;
 etemp=even;

 while(temp!=NULL)
 {

 if( toggle == 1)
 {

   otemp-next=temp;
   otemp=otemp-next;

   temp=temp-next;
   otemp-next=NULL;

   toggle=0;
 }
 else
 {
   etemp-next=temp;
   etemp=etemp-next;

   temp=temp-next;
   etemp-next=NULL;

   toggle=1;

 }



 }


 }

 On Sat, Dec 24, 2011 at 10:56 PM, Karthikeyan V.B kartmu...@gmail.comwrote:

 Segregate even and odd psoitioned nodes in a linked list

 Eg:
 2-3-1-9-7-5
 The output should be two separate lists
 2-1-7
 3-9-5

 *My code is:*
 void segregate(node* head)
 {
 int i=1;
 node* sec=head-next;
 node *odd=head,*even=head-next;
 while(even)
 {
 if(i%2)
 {
 odd-next=even-next;
 even-next=NULL;
 odd=odd-next;
 if(!odd-next) break;
 }
 else
 {
 even-next=odd-next;
 odd-next=NULL;
 even=even-next;
 if(!even-next) break;
 }
 i++;
 }
 }

 Pls correct me if i'm wrong or suggest me a better approach

 Regards,
 KARTHIKEYAN.V.B
 PSGTECH
 CBE

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST

2011-12-25 Thread atul anand
@ashish : please provide link for that page

On Sun, Dec 25, 2011 at 10:36 PM, Ashish Goel ashg...@gmail.com wrote:

 refer stanford page
 1,2,3,4,5,6

 will become

 5,3,1
 6,4,2

 void MoveNode(struct node** destRef, struct node** sourceRef) {
 struct node* newNode = *sourceRef; // the front source node
 assert(newNode != NULL);
 *sourceRef = newNode-next; // Advance the source pointer
 newNode-next = *destRef; // Link the old dest off the new node
 *destRef = newNode; // Move dest to point to the new node
 }

 void AlternatingSplit(struct node* source,
 struct node** aRef, struct node** bRef) {
 struct node* a = NULL; // Split the nodes to these 'a' and 'b' lists
 struct node* b = NULL;
 struct node* current = source;
 while (current != NULL) {
 MoveNode(a, current); // Move a node to 'a'
 if (current != NULL) {
 MoveNode(b, current); // Move a node to 'b'
 }
 }
 *aRef = a;
 *bRef = b;
 }


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652



 On Sat, Dec 24, 2011 at 11:37 PM, atul anand atul.87fri...@gmail.comwrote:

 because you are doing odd=odd-next; and even=even-next;
 you will lose head pointers for the two linked list formed once you come
 out of the loop.



 void segregate(node* head)
 {
 node *temp,*odd,*even;
 toggle=1;
 if(head==NULL)
 {
  return;
 }
 odd=head;

 if(head-next==NULL)
 {

  return;
 }
 even=head-next;

 if(even-next==NULL)
 {
   return;
 }
 else
 {
   temp=even-next;
 }
 node *otemp,*etemp;
 otemp=odd;
 etemp=even;

 while(temp!=NULL)
 {

 if( toggle == 1)
 {

   otemp-next=temp;
   otemp=otemp-next;

   temp=temp-next;
   otemp-next=NULL;

   toggle=0;
 }
 else
 {
   etemp-next=temp;
   etemp=etemp-next;

   temp=temp-next;
   etemp-next=NULL;

   toggle=1;

 }



 }


 }

 On Sat, Dec 24, 2011 at 10:56 PM, Karthikeyan V.B kartmu...@gmail.comwrote:

 Segregate even and odd psoitioned nodes in a linked list

 Eg:
 2-3-1-9-7-5
 The output should be two separate lists
 2-1-7
 3-9-5

 *My code is:*
 void segregate(node* head)
 {
 int i=1;
 node* sec=head-next;
 node *odd=head,*even=head-next;
 while(even)
 {
 if(i%2)
 {
 odd-next=even-next;
 even-next=NULL;
 odd=odd-next;
 if(!odd-next) break;
 }
 else
 {
 even-next=odd-next;
 odd-next=NULL;
 even=even-next;
 if(!even-next) break;
 }
 i++;
 }
 }

 Pls correct me if i'm wrong or suggest me a better approach

 Regards,
 KARTHIKEYAN.V.B
 PSGTECH
 CBE

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] LINKED LIST

2011-12-25 Thread atul anand
@ashish : acc to  Karthikeyan  question ...output should not be in reverse
order.

there is not much difference b/w both implementation.

it will become little interesting if you try to solve using recursion .

On Sun, Dec 25, 2011 at 10:36 PM, Ashish Goel ashg...@gmail.com wrote:

 refer stanford page
 1,2,3,4,5,6

 will become

 5,3,1
 6,4,2

 void MoveNode(struct node** destRef, struct node** sourceRef) {
 struct node* newNode = *sourceRef; // the front source node
 assert(newNode != NULL);
 *sourceRef = newNode-next; // Advance the source pointer
 newNode-next = *destRef; // Link the old dest off the new node
 *destRef = newNode; // Move dest to point to the new node
 }

 void AlternatingSplit(struct node* source,
 struct node** aRef, struct node** bRef) {
 struct node* a = NULL; // Split the nodes to these 'a' and 'b' lists
 struct node* b = NULL;
 struct node* current = source;
 while (current != NULL) {
 MoveNode(a, current); // Move a node to 'a'
 if (current != NULL) {
 MoveNode(b, current); // Move a node to 'b'
 }
 }
 *aRef = a;
 *bRef = b;
 }


 Best Regards
 Ashish Goel
 Think positive and find fuel in failure
 +919985813081
 +919966006652



 On Sat, Dec 24, 2011 at 11:37 PM, atul anand atul.87fri...@gmail.comwrote:

 because you are doing odd=odd-next; and even=even-next;
 you will lose head pointers for the two linked list formed once you come
 out of the loop.



 void segregate(node* head)
 {
 node *temp,*odd,*even;
 toggle=1;
 if(head==NULL)
 {
  return;
 }
 odd=head;

 if(head-next==NULL)
 {

  return;
 }
 even=head-next;

 if(even-next==NULL)
 {
   return;
 }
 else
 {
   temp=even-next;
 }
 node *otemp,*etemp;
 otemp=odd;
 etemp=even;

 while(temp!=NULL)
 {

 if( toggle == 1)
 {

   otemp-next=temp;
   otemp=otemp-next;

   temp=temp-next;
   otemp-next=NULL;

   toggle=0;
 }
 else
 {
   etemp-next=temp;
   etemp=etemp-next;

   temp=temp-next;
   etemp-next=NULL;

   toggle=1;

 }



 }


 }

 On Sat, Dec 24, 2011 at 10:56 PM, Karthikeyan V.B kartmu...@gmail.comwrote:

 Segregate even and odd psoitioned nodes in a linked list

 Eg:
 2-3-1-9-7-5
 The output should be two separate lists
 2-1-7
 3-9-5

 *My code is:*
 void segregate(node* head)
 {
 int i=1;
 node* sec=head-next;
 node *odd=head,*even=head-next;
 while(even)
 {
 if(i%2)
 {
 odd-next=even-next;
 even-next=NULL;
 odd=odd-next;
 if(!odd-next) break;
 }
 else
 {
 even-next=odd-next;
 odd-next=NULL;
 even=even-next;
 if(!even-next) break;
 }
 i++;
 }
 }

 Pls correct me if i'm wrong or suggest me a better approach

 Regards,
 KARTHIKEYAN.V.B
 PSGTECH
 CBE

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] LINKED LIST

2011-12-24 Thread Karthikeyan V.B
Segregate even and odd psoitioned nodes in a linked list

Eg:
2-3-1-9-7-5
The output should be two separate lists
2-1-7
3-9-5

*My code is:*
void segregate(node* head)
{
int i=1;
node* sec=head-next;
node *odd=head,*even=head-next;
while(even)
{
if(i%2)
{
odd-next=even-next;
even-next=NULL;
odd=odd-next;
if(!odd-next) break;
}
else
{
even-next=odd-next;
odd-next=NULL;
even=even-next;
if(!even-next) break;
}
i++;
}
}

Pls correct me if i'm wrong or suggest me a better approach

Regards,
KARTHIKEYAN.V.B
PSGTECH
CBE

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



Re: [algogeeks] LINKED LIST

2011-12-24 Thread atul anand
because you are doing odd=odd-next; and even=even-next;
you will lose head pointers for the two linked list formed once you come
out of the loop.



void segregate(node* head)
{
node *temp,*odd,*even;
toggle=1;
if(head==NULL)
{
 return;
}
odd=head;

if(head-next==NULL)
{

 return;
}
even=head-next;

if(even-next==NULL)
{
  return;
}
else
{
  temp=even-next;
}
node *otemp,*etemp;
otemp=odd;
etemp=even;

while(temp!=NULL)
{

if( toggle == 1)
{

  otemp-next=temp;
  otemp=otemp-next;

  temp=temp-next;
  otemp-next=NULL;

  toggle=0;
}
else
{
  etemp-next=temp;
  etemp=etemp-next;

  temp=temp-next;
  etemp-next=NULL;

  toggle=1;

}



}


}

On Sat, Dec 24, 2011 at 10:56 PM, Karthikeyan V.B kartmu...@gmail.comwrote:

 Segregate even and odd psoitioned nodes in a linked list

 Eg:
 2-3-1-9-7-5
 The output should be two separate lists
 2-1-7
 3-9-5

 *My code is:*
 void segregate(node* head)
 {
 int i=1;
 node* sec=head-next;
 node *odd=head,*even=head-next;
 while(even)
 {
 if(i%2)
 {
 odd-next=even-next;
 even-next=NULL;
 odd=odd-next;
 if(!odd-next) break;
 }
 else
 {
 even-next=odd-next;
 odd-next=NULL;
 even=even-next;
 if(!even-next) break;
 }
 i++;
 }
 }

 Pls correct me if i'm wrong or suggest me a better approach

 Regards,
 KARTHIKEYAN.V.B
 PSGTECH
 CBE

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked List Problem-Suggest Algo

2011-11-21 Thread Piyush Grover
As you mentioned, the numbers designating the gaps can only be repeated
so in your example 2 20 can be broken into 19 1 but 19 is already there in
the list (the
first couplet) and it's not the one which describes the gap. can you please
clarify?

On Mon, Nov 21, 2011 at 5:23 AM, Ankur Garg ankurga...@gmail.com wrote:

 a linked list contains
 2 19 _ _ 3 47 _ _ _ 2 20 _ _ ..and so on
 I have to fill those empty nodes with numbers whose sum is equal to the
 numbers
 occurring just before the gaps and the number of gaps is determined by the
 node
 which is at 2 distance before the gaps with the limitation that their
 would be no
 repetition in list only the nodes designating the number of gaps can be
 repeated
 for example 2 20 should be broken in two parts like 19 1
 3 47 should be broken in three parts like 42 2 3
 and not in 44 1 2 because 1 already occurred in the list due previous
 partition



  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Linked List Problem-Suggest Algo

2011-11-20 Thread Ankur Garg
a linked list contains
2 19 _ _ 3 47 _ _ _ 2 20 _ _ ..and so on
I have to fill those empty nodes with numbers whose sum is equal to the
numbers
occurring just before the gaps and the number of gaps is determined by the
node
which is at 2 distance before the gaps with the limitation that their would
be no
repetition in list only the nodes designating the number of gaps can be
repeated
for example 2 20 should be broken in two parts like 19 1
3 47 should be broken in three parts like 42 2 3
and not in 44 1 2 because 1 already occurred in the list due previous
partition

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



[algogeeks] Linked List Problem

2011-09-29 Thread Ankuj Gupta
There are two linked list of length m and n. There is some common data
at the end of both. Find the starting position in both the linked
list. I could suggest two methods

1) Reverse the list and check .
2) Use recursion to go to the last element and move back from there.

Is there any other way ?

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



Re: [algogeeks] Linked List Problem

2011-09-29 Thread prasanth n
consider the length of list1 is 7(ie m) and length of list2 is 5 (ie n)..now
find (m-n) ie 7-5=2..since length of list2 is smaller than list1,,have a
pointer pointing to the head of the list2 and move that pointer (m-n)
positions ie (here 2 positions)..now have a pointer pointing to the head of
list1 and also list2's pointer points to 3rd node(since we have moved 2
nodes)..now compare both the list's data part..if they are different,,move
both de pointer's by one node..continue doing this till you reach the
intersection point..if they both have same data,,that is the intersection
point

On Thu, Sep 29, 2011 at 10:38 PM, Ankuj Gupta ankuj2...@gmail.com wrote:

 There are two linked list of length m and n. There is some common data
 at the end of both. Find the starting position in both the linked
 list. I could suggest two methods

 1) Reverse the list and check .
 2) Use recursion to go to the last element and move back from there.

 Is there any other way ?

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




-- 
*prasanth*

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



Re: [algogeeks] Linked List Problem

2011-09-29 Thread annarao kataru
@prasanth   but how can u know that it will start after the difference
of the number of nodes (m-n) .  they may be similar even after  one
element also ??

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



Re: [algogeeks] Linked List Problem

2011-09-29 Thread partik madan
@annarao : as the common data is at the end of the linked lists so the
length of common data can not be greater than the length of shorter linked
list . so i think prasanth is right  !!





-- 
*Partik Madan*
Computer Engg.
NIT Kurukshetra

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



Re: [algogeeks] Linked List Problem

2011-09-29 Thread annarao kataru
@partik oh  i  forgot  it  thank  u for ur clarification..

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



Re: [algogeeks] Linked List Problem

2011-09-29 Thread siddharam suresh
@Ankuj Gupta: your algo wont work

see,what happens when ur algo run.

list1 1-2-3-4-5-6
list2 9-8-4-5-6

reverse list 1
list1 6-5-4-3-2-1
   6-5-4
 ^
 |
list2  8-9

reverse list 2

list1 6-5-4-9-8
list2  4-9-8

Thank you,
Sid.


On Fri, Sep 30, 2011 at 9:37 AM, annarao kataru kataruanna...@gmail.com wrote:

 @partik     oh  i  forgot  it  thank  u for ur clarification..

 --
 You received this message because you are subscribed to the Google Groups 
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to 
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked List Problem

2011-09-29 Thread sukran dhawan
find length of linked list 1 say m
find length of linked list2 say n
take mod(m-n) say k

traverse k nodes in bigger lis
after that both listts one position at a time until the pointers are equal

On Fri, Sep 30, 2011 at 9:34 AM, partik madan partikma...@gmail.com wrote:

 @annarao : as the common data is at the end of the linked lists so the
 length of common data can not be greater than the length of shorter linked
 list . so i think prasanth is right  !!





 --
 *Partik Madan*
 Computer Engm-n g.
 NIT Kurukshetra


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Linked list

2011-07-15 Thread Nishant Mittal
delete all the numbers found in list2 from list1 recursively or iteratively
Also optimize ur algo when list1 is sorted in ascending order and list2 is
sorted in descending order

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



Re: [algogeeks] Linked list

2011-07-15 Thread surender sanke
count number of elements from both lists and reverse list with minimum
number of elements, go ahead with checking and deleting linearly

surender

On Fri, Jul 15, 2011 at 10:38 PM, Nishant Mittal mittal.nishan...@gmail.com
 wrote:

 delete all the numbers found in list2 from list1 recursively or iteratively
 Also optimize ur algo when list1 is sorted in ascending order and list2 is
 sorted in descending order

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked list

2011-07-15 Thread Nishant Mittal
@surender thanx for ur algo but tell me about the 1st part when numbers are
not sorted.
i think if we apply merge sort on both the list then it would be easy to
delete after sorting.
correct me if i m wrong

On Sat, Jul 16, 2011 at 12:40 AM, surender sanke surend...@gmail.comwrote:

 count number of elements from both lists and reverse list with minimum
 number of elements, go ahead with checking and deleting linearly

 surender

 On Fri, Jul 15, 2011 at 10:38 PM, Nishant Mittal 
 mittal.nishan...@gmail.com wrote:

 delete all the numbers found in list2 from list1 recursively or
 iteratively
 Also optimize ur algo when list1 is sorted in ascending order and list2 is
 sorted in descending order

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Linked list

2011-07-15 Thread surender sanke
if lists are unordered, make a map of list2 and during traversal of list1
search for map, if found delete that node

surender

On Sat, Jul 16, 2011 at 2:02 AM, Nishant Mittal
mittal.nishan...@gmail.comwrote:

 @surender thanx for ur algo but tell me about the 1st part when numbers are
 not sorted.
 i think if we apply merge sort on both the list then it would be easy to
 delete after sorting.
 correct me if i m wrong


 On Sat, Jul 16, 2011 at 12:40 AM, surender sanke surend...@gmail.comwrote:

 count number of elements from both lists and reverse list with minimum
 number of elements, go ahead with checking and deleting linearly

 surender

 On Fri, Jul 15, 2011 at 10:38 PM, Nishant Mittal 
 mittal.nishan...@gmail.com wrote:

 delete all the numbers found in list2 from list1 recursively or
 iteratively
 Also optimize ur algo when list1 is sorted in ascending order and list2
 is sorted in descending order

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] linked list doubt

2011-07-11 Thread Anika Jain
*if i have to write a code for finding middle element in a linked list..
then for even length linked which will be the middle element both n/2-1 and
n/2+1 or just n/2+1???

if its both then how can i make my function two elements??
*

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



Re: [algogeeks] linked list doubt

2011-07-11 Thread vaibhav shukla
 i have considered it  (n/2+1)th
and didn't bothered much :P


On Mon, Jul 11, 2011 at 4:57 PM, Anika Jain anika.jai...@gmail.com wrote:

 *if i have to write a code for finding middle element in a linked list..
 then for even length linked which will be the middle element both n/2-1 and
 n/2+1 or just n/2+1???

 if its both then how can i make my function two elements??
 *

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




-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

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



Re: [algogeeks] linked list doubt

2011-07-11 Thread chandy jose paul
dnt worry about that write a code in which initialy 2 ptrs .move 1 ptr 2
nodes at a time and other ptr 1 time.when the first ptr reaches end then
seconf ptr will be at middle

On Mon, Jul 11, 2011 at 6:15 PM, vaibhav shukla vaibhav200...@gmail.comwrote:

  i have considered it  (n/2+1)th
 and didn't bothered much :P



 On Mon, Jul 11, 2011 at 4:57 PM, Anika Jain anika.jai...@gmail.comwrote:

 *if i have to write a code for finding middle element in a linked list..
 then for even length linked which will be the middle element both n/2-1 and
 n/2+1 or just n/2+1???

 if its both then how can i make my function two elements??
 *

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




 --
   best wishes!!
 Vaibhav Shukla
 DU-MCA


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list doubt

2011-07-11 Thread vaibhav shukla
moreover n/2-1 will never be the middle element. in case of even no. of
nodes ,middle shall be n/2 and n/2+1

On Mon, Jul 11, 2011 at 6:19 PM, chandy jose paul jpchaa...@gmail.comwrote:

 dnt worry about that write a code in which initialy 2 ptrs .move 1 ptr 2
 nodes at a time and other ptr 1 time.when the first ptr reaches end then
 seconf ptr will be at middle

 On Mon, Jul 11, 2011 at 6:15 PM, vaibhav shukla 
 vaibhav200...@gmail.comwrote:

  i have considered it  (n/2+1)th
 and didn't bothered much :P



 On Mon, Jul 11, 2011 at 4:57 PM, Anika Jain anika.jai...@gmail.comwrote:

 *if i have to write a code for finding middle element in a linked list..
 then for even length linked which will be the middle element both n/2-1 and
 n/2+1 or just n/2+1???

 if its both then how can i make my function two elements??
 *

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




 --
   best wishes!!
 Vaibhav Shukla
 DU-MCA


  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
  best wishes!!
Vaibhav Shukla
DU-MCA

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



Re: [algogeeks] linked list

2011-07-05 Thread sagar pareek
yeah.
it totally depends on the no. of data fields :)

On Mon, Jul 4, 2011 at 2:03 PM, sunny agrawal sunny816.i...@gmail.comwrote:

 @Sagar
 if it has a large no of data fields than don't u think just changing
 pointers will be much better than swapping all the data contained in the
 node

 On Mon, Jul 4, 2011 at 11:13 AM, sagar pareek sagarpar...@gmail.comwrote:

 @Anantha Krishnan
 Well be specific
 just read the question again. it has only to reorder numbers...
 what problem will occur if it has more than one data fields
 we can traverse with help of digits and then swap all the data fields


 On Thu, Jun 30, 2011 at 5:03 PM, Anantha Krishnan 
 ananthakrishnan@gmail.com wrote:

 @sagar pareek
 If there are more fields in the node like:

 struct node{
  int data;
  float mark;
  char ch;
  struct node *link;
 };
 Here swapping *data* alone will corrupt the list right!!


 On Thu, Jun 30, 2011 at 4:38 PM, sagar pareek sagarpar...@gmail.comwrote:

 Here is one approach which works :)

 Traverse the list from a pointer name ptr
 when encounter odd then start traversing from a tmp pointer (start point
 is ptr-next) to find even no. when find it swap the numbers.
 then again start forwarding ptr. If during traversing  ptr==tmp make
 flag=0(at start make it flag=1) if again ptr encounter odd then if flag=0
 then tmp=ptr-next else tmp=tmp-next
 do it until tmp or ptr becomes null. :)
 I hope no questions :) :)


 On Thu, Jun 30, 2011 at 12:01 PM, Rohan Kalra 
 ronziiretu...@gmail.comwrote:

 http://geeksforgeeks.org/?p=12000
 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/OnLux79bj3MJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

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




 --
 Sunny Aggrawal
 B-Tech IV year,CSI
 Indian Institute Of Technology,Roorkee


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




-- 
Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

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



Re: [algogeeks] linked list

2011-07-04 Thread sunny agrawal
@Sagar
if it has a large no of data fields than don't u think just changing
pointers will be much better than swapping all the data contained in the
node

On Mon, Jul 4, 2011 at 11:13 AM, sagar pareek sagarpar...@gmail.com wrote:

 @Anantha Krishnan
 Well be specific
 just read the question again. it has only to reorder numbers...
 what problem will occur if it has more than one data fields
 we can traverse with help of digits and then swap all the data fields


 On Thu, Jun 30, 2011 at 5:03 PM, Anantha Krishnan 
 ananthakrishnan@gmail.com wrote:

 @sagar pareek
 If there are more fields in the node like:

 struct node{
  int data;
  float mark;
  char ch;
  struct node *link;
 };
 Here swapping *data* alone will corrupt the list right!!


 On Thu, Jun 30, 2011 at 4:38 PM, sagar pareek sagarpar...@gmail.comwrote:

 Here is one approach which works :)

 Traverse the list from a pointer name ptr
 when encounter odd then start traversing from a tmp pointer (start point
 is ptr-next) to find even no. when find it swap the numbers.
 then again start forwarding ptr. If during traversing  ptr==tmp make
 flag=0(at start make it flag=1) if again ptr encounter odd then if flag=0
 then tmp=ptr-next else tmp=tmp-next
 do it until tmp or ptr becomes null. :)
 I hope no questions :) :)


 On Thu, Jun 30, 2011 at 12:01 PM, Rohan Kalra 
 ronziiretu...@gmail.comwrote:

 http://geeksforgeeks.org/?p=12000

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/OnLux79bj3MJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

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




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

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



Re: [algogeeks] linked list

2011-07-03 Thread sagar pareek
@Anantha Krishnan
Well be specific
just read the question again. it has only to reorder numbers...
what problem will occur if it has more than one data fields
we can traverse with help of digits and then swap all the data fields

On Thu, Jun 30, 2011 at 5:03 PM, Anantha Krishnan 
ananthakrishnan@gmail.com wrote:

 @sagar pareek
 If there are more fields in the node like:

 struct node{
  int data;
  float mark;
  char ch;
  struct node *link;
 };
 Here swapping *data* alone will corrupt the list right!!


 On Thu, Jun 30, 2011 at 4:38 PM, sagar pareek sagarpar...@gmail.comwrote:

 Here is one approach which works :)

 Traverse the list from a pointer name ptr
 when encounter odd then start traversing from a tmp pointer (start point
 is ptr-next) to find even no. when find it swap the numbers.
 then again start forwarding ptr. If during traversing  ptr==tmp make
 flag=0(at start make it flag=1) if again ptr encounter odd then if flag=0
 then tmp=ptr-next else tmp=tmp-next
 do it until tmp or ptr becomes null. :)
 I hope no questions :) :)


 On Thu, Jun 30, 2011 at 12:01 PM, Rohan Kalra ronziiretu...@gmail.comwrote:

 http://geeksforgeeks.org/?p=12000

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/OnLux79bj3MJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

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



Re: [algogeeks] linked list

2011-06-30 Thread Rohan Kalra
http://geeksforgeeks.org/?p=12000

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/algogeeks/-/OnLux79bj3MJ.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list

2011-06-30 Thread sagar pareek
Here is one approach which works :)

Traverse the list from a pointer name ptr
when encounter odd then start traversing from a tmp pointer (start point is
ptr-next) to find even no. when find it swap the numbers.
then again start forwarding ptr. If during traversing  ptr==tmp make
flag=0(at start make it flag=1) if again ptr encounter odd then if flag=0
then tmp=ptr-next else tmp=tmp-next
do it until tmp or ptr becomes null. :)
I hope no questions :) :)

On Thu, Jun 30, 2011 at 12:01 PM, Rohan Kalra ronziiretu...@gmail.comwrote:

 http://geeksforgeeks.org/?p=12000

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/OnLux79bj3MJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
**Regards
SAGAR PAREEK
COMPUTER SCIENCE AND ENGINEERING
NIT ALLAHABAD

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



Re: [algogeeks] linked list

2011-06-30 Thread Anantha Krishnan
Check this
http://ideone.com/1I40z

On Wed, Jun 29, 2011 at 8:04 PM, Nishant Mittal
mittal.nishan...@gmail.comwrote:

 segregate even and odd nodes in a singly linked list.Order of even and
 odd numbers must be same...
 e.g:-
 i/p list is 4-1-3-6-12-8-7-NULL
 o/p list  4-6-12-8-1-3-7-NULL

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list

2011-06-30 Thread Anantha Krishnan
@sagar pareek
If there are more fields in the node like:

struct node{
 int data;
 float mark;
 char ch;
 struct node *link;
};
Here swapping *data* alone will corrupt the list right!!


On Thu, Jun 30, 2011 at 4:38 PM, sagar pareek sagarpar...@gmail.com wrote:

 Here is one approach which works :)

 Traverse the list from a pointer name ptr
 when encounter odd then start traversing from a tmp pointer (start point is
 ptr-next) to find even no. when find it swap the numbers.
 then again start forwarding ptr. If during traversing  ptr==tmp make
 flag=0(at start make it flag=1) if again ptr encounter odd then if flag=0
 then tmp=ptr-next else tmp=tmp-next
 do it until tmp or ptr becomes null. :)
 I hope no questions :) :)


 On Thu, Jun 30, 2011 at 12:01 PM, Rohan Kalra ronziiretu...@gmail.comwrote:

 http://geeksforgeeks.org/?p=12000

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To view this discussion on the web visit
 https://groups.google.com/d/msg/algogeeks/-/OnLux79bj3MJ.

 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 **Regards
 SAGAR PAREEK
 COMPUTER SCIENCE AND ENGINEERING
 NIT ALLAHABAD

  --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] linked list

2011-06-29 Thread Nishant Mittal
segregate even and odd nodes in a singly linked list.Order of even and
odd numbers must be same...
e.g:-
i/p list is 4-1-3-6-12-8-7-NULL
o/p list  4-6-12-8-1-3-7-NULL

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



Re: [algogeeks] linked list

2011-06-29 Thread sunny agrawal
maintain two pointers one at the tail of even number list one at tail of odd
Number list
traverse the list and add the number at required list

On Wed, Jun 29, 2011 at 8:04 PM, Nishant Mittal
mittal.nishan...@gmail.comwrote:

 segregate even and odd nodes in a singly linked list.Order of even and
 odd numbers must be same...
 e.g:-
 i/p list is 4-1-3-6-12-8-7-NULL
 o/p list  4-6-12-8-1-3-7-NULL

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




-- 
Sunny Aggrawal
B-Tech IV year,CSI
Indian Institute Of Technology,Roorkee

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



Re: [algogeeks] linked list

2011-06-29 Thread Piyush Sinha
node *segregate(node *head)
{
node *even,*odd,*even1,*odd1;
even=odd=NULL;
while(head)
{
if((head-data)%2)  
{
if(!odd)
{
odd = head;
odd1 = odd;
}
else
{
odd1-next = head;
odd1 = odd1-next;
}
}
else
{
if(!even)
{
even = head;
even1 = even;
}
else
{
even1-next = head;
even1 = even1-next;
}
}
head=head-next;
}
odd1-next=NULL;
even1-next = odd;
return (even);
}

On 6/29/11, Nishant Mittal mittal.nishan...@gmail.com wrote:
 segregate even and odd nodes in a singly linked list.Order of even and
 odd numbers must be same...
 e.g:-
 i/p list is 4-1-3-6-12-8-7-NULL
 o/p list  4-6-12-8-1-3-7-NULL

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




-- 
*Piyush Sinha*
*IIIT, Allahabad*
*+91-8792136657*
*+91-7483122727*
*https://www.facebook.com/profile.php?id=10655377926 *

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



[algogeeks] linked list

2011-03-16 Thread himanshu kansal
can nodes of linked list in c/c++ contain different types of
datameans suppose 1st node of the list contains an integer value,
2nd contains a float,3rd has a string and so on..

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



Re: [algogeeks] linked list

2011-03-16 Thread Balaji Ramani
1) You can use void* as the data part and then allocate memory separately
and use.

struct node
{
  void* dataPtr;
  struct node* next;
};

2) or Use embeddable lists:
http://isis.poly.edu/kulesh/stuff/src/klist/

Thanks,
Balaji.

On Wed, Mar 16, 2011 at 8:27 PM, himanshu kansal 
himanshukansal...@gmail.com wrote:

 can nodes of linked list in c/c++ contain different types of
 datameans suppose 1st node of the list contains an integer value,
 2nd contains a float,3rd has a string and so on..

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Linked List Amazon

2011-02-16 Thread bittu
Given a linked list structure where every node represents a linked
list and contains two pointers of its type:
(i) pointer to next node in the main list.
(ii) pointer to a linked list where this node is head.

Write a C function to flatten the list into a single linked list.

Eg.

If the given linked list is
 1 -- 5 -- 7 -- 10
 |   |  |
 2 6 8
 |   |
 3 9
 |
 4

then convert it to
 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 -10

Thanks  Regards
Shashank Mani

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



Re: [algogeeks] Linked List Amazon

2011-02-16 Thread nphard nphard
Node *flatten(Node *node) {
if (!node)
return NULL;
Node *head = node;
Node *next = node-next;
node-next = NULL;
if (node-down)
node-next = flatten(node-down);
while (node-next != NULL)
node = node-next;
node-next = flatten(next);
return head;
}



On Wed, Feb 16, 2011 at 8:38 PM, bittu shashank7andr...@gmail.com wrote:

 Given a linked list structure where every node represents a linked
 list and contains two pointers of its type:
 (i) pointer to next node in the main list.
 (ii) pointer to a linked list where this node is head.

 Write a C function to flatten the list into a single linked list.

 Eg.

 If the given linked list is
  1 -- 5 -- 7 -- 10
  |   |  |
  2 6 8
  |   |
  3 9
  |
  4

 then convert it to
  1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 -10

 Thanks  Regards
 Shashank Mani

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 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 algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] linked list as tree

2010-08-23 Thread Raj N
Hi,
Could anyone help me representing linked list in the form a binary
tree ?

Thanks !!

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



Re: [algogeeks] linked list as tree

2010-08-23 Thread Yan Wang
Actually, a linear data structure like a linked list is also a
specific kind of tree structure.

2010/8/23 Raj N rajn...@gmail.com:
 Hi,
 Could anyone help me representing linked list in the form a binary
 tree ?

 Thanks !!

 --
 You received this message because you are subscribed to the Google Groups 
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to 
 algogeeks+unsubscr...@googlegroups.com.
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list as tree

2010-08-23 Thread Raj N
What will be the representation. How do you define left and right pointers
of the tree for a linked list.

On Mon, Aug 23, 2010 at 10:35 PM, Yan Wang wangyanadam1...@gmail.comwrote:

 Actually, a linear data structure like a linked list is also a
 specific kind of tree structure.

 2010/8/23 Raj N rajn...@gmail.com:
  Hi,
  Could anyone help me representing linked list in the form a binary
  tree ?
 
  Thanks !!
 
  --
  You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list

2010-08-20 Thread ram das
that's because you are creating char str[20]; on the stack so when the
function createList completes all str [20] will be deleted from stack as a
part of stack unwinding. and next you are calling display where all the
references to name is removed and you are getting gabage value.to avoid this
you need to allocate dinamic memory for str.

ouy should use  char *str= (char*)malloc(20*sizeof(char))in function
createList ; instead of
str[20];


On Thu, Aug 19, 2010 at 10:31 PM, Raj Jagvanshi raj.jagvan...@gmail.comwrote:

 my display function print garbage value from begining

 On Thu, Aug 19, 2010 at 5:22 PM, vineeth mohan 
 vm.vineethmo...@gmail.comwrote:

 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }


 when head reaches last node
 condition head is true , then head will become head-next which is null ,
 and it will try to print the name field from of a null value which is error

  On Wed, Aug 18, 2010 at 10:53 PM, Raj Jagvanshi raj.jagvan...@gmail.com
  wrote:

  wats d problem in my display()




 #includeiostream
 #includemalloc.h
 #include string.h

 using namespace std;
 struct node
 {
 char *name;
 struct node *next;
 };
 typedef struct node Node;

 void createList(Node **head )
 {
 char str[20];
 char *p;
 coutEnter a String:   ;
 gets (str) ;
 p = str;
 if((strlen(p))2)
  return;
 Node *temp=*head;
 Node *newnode=(Node*)malloc(sizeof(Node));
 newnode-name=p;
 newnode-next=NULL;
 if(!temp)
 *head = newnode;
 else
 {
 while(temp-next)
temp = temp-next;
 temp-next = newnode;
 }
 createList(head);
 }
 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }
 int main()
 {
 Node *head=NULL;
 while(1)
 {
 cout\n\t\tMENU\n;
 cout0   : To exit.\n;
 cout1   : To create a linear link list.\n;
 cout2   : To display the list.\n;
 char choice;
 choice = getchar();
 getchar();
 if(choice=='0')
 break;
 switch(choice)
 {
 case '1':
 createList(head );
 break;
  case '2':
 display(head);
 break;
 default:
 coutEnter valid choice.;
}
 }
 system(pause);
 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Thanks  Regards
Ram Narayan Das
mob: +91 9177711195

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



Re: [algogeeks] linked list

2010-08-20 Thread Raj Jagvanshi
#includeiostream
#includemalloc.h
#include string.h

using namespace std;
struct node
{
void *name;
struct node *next;
};
typedef struct node Node;

void createList(Node **head )
{
char *str= (char*)malloc(20*sizeof(char));
char *p;
coutEnter a String:   ;
gets (str) ;
p = str;
if((strlen(p))2)
 return;
Node *temp=*head;
Node *newnode=(Node*)malloc(sizeof(Node));
newnode-name=p;
newnode-next=NULL;
if(!temp)
*head = newnode;
else
{
while(temp-next)
   temp = temp-next;
temp-next = newnode;
}
createList(head);
}
void display(Node *head)
{
 cout\n;
 for( ; head ; head=head-next)
cout\thead-name;
 cout\n;
}
int main()
{
Node *head=NULL;
while(1)
{
cout\n\t\tMENU\n;
cout0   : To exit.\n;
cout1   : To create a linear link list.\n;
cout2   : To display the list.\n;
char choice;
cinchoice;

if(choice=='0')
break;
switch(choice)
{
case '1':
createList(head );
break;
 case '2':
display(head);
break;
default:
coutEnter valid choice.;
   }
}
system(pause);
return 0;
}
solve my problem

On Fri, Aug 20, 2010 at 12:09 PM, ram das ramnaraya...@gmail.com wrote:

 that's because you are creating char str[20]; on the stack so when the
 function createList completes all str [20] will be deleted from stack as a
 part of stack unwinding. and next you are calling display where all the
 references to name is removed and you are getting gabage value.to avoid
 this you need to allocate dinamic memory for str.

 ouy should use  char *str= (char*)malloc(20*sizeof(char))in function
 createList ; instead of
 str[20];



 On Thu, Aug 19, 2010 at 10:31 PM, Raj Jagvanshi 
 raj.jagvan...@gmail.comwrote:

 my display function print garbage value from begining

 On Thu, Aug 19, 2010 at 5:22 PM, vineeth mohan vm.vineethmo...@gmail.com
  wrote:

 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }


 when head reaches last node
 condition head is true , then head will become head-next which is null ,
 and it will try to print the name field from of a null value which is error

  On Wed, Aug 18, 2010 at 10:53 PM, Raj Jagvanshi 
 raj.jagvan...@gmail.com wrote:

  wats d problem in my display()




 #includeiostream
 #includemalloc.h
 #include string.h

 using namespace std;
 struct node
 {
 char *name;
 struct node *next;
 };
 typedef struct node Node;

 void createList(Node **head )
 {
 char str[20];
 char *p;
 coutEnter a String:   ;
 gets (str) ;
 p = str;
 if((strlen(p))2)
  return;
 Node *temp=*head;
 Node *newnode=(Node*)malloc(sizeof(Node));
 newnode-name=p;
 newnode-next=NULL;
 if(!temp)
 *head = newnode;
 else
 {
 while(temp-next)
temp = temp-next;
 temp-next = newnode;
 }
 createList(head);
 }
 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }
 int main()
 {
 Node *head=NULL;
 while(1)
 {
 cout\n\t\tMENU\n;
 cout0   : To exit.\n;
 cout1   : To create a linear link list.\n;
 cout2   : To display the list.\n;
 char choice;
 choice = getchar();
 getchar();
 if(choice=='0')
 break;
 switch(choice)
 {
 case '1':
 createList(head );
 break;
  case '2':
 display(head);
 break;
 default:
 coutEnter valid choice.;
}
 }
 system(pause);
 return 0;
 }

 --
 You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 

[algogeeks] linked list

2010-08-19 Thread Raj Jagvanshi
wats d problem in my display()




#includeiostream
#includemalloc.h
#include string.h

using namespace std;
struct node
{
char *name;
struct node *next;
};
typedef struct node Node;

void createList(Node **head )
{
char str[20];
char *p;
coutEnter a String:   ;
gets (str) ;
p = str;
if((strlen(p))2)
 return;
Node *temp=*head;
Node *newnode=(Node*)malloc(sizeof(Node));
newnode-name=p;
newnode-next=NULL;
if(!temp)
*head = newnode;
else
{
while(temp-next)
   temp = temp-next;
temp-next = newnode;
}
createList(head);
}
void display(Node *head)
{
 cout\n;
 for( ; head ; head=head-next)
cout\thead-name;
 cout\n;
}
int main()
{
Node *head=NULL;
while(1)
{
cout\n\t\tMENU\n;
cout0   : To exit.\n;
cout1   : To create a linear link list.\n;
cout2   : To display the list.\n;
char choice;
choice = getchar();
getchar();
if(choice=='0')
break;
switch(choice)
{
case '1':
createList(head );
break;
 case '2':
display(head);
break;
default:
coutEnter valid choice.;
   }
}
system(pause);
return 0;
}

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



Re: [algogeeks] linked list

2010-08-19 Thread ram das
make declaration of char str[20] to  char
*str=(char*)malloc(20*sizeof(char));
and it will work .

On Wed, Aug 18, 2010 at 11:23 PM, Raj Jagvanshi raj.jagvan...@gmail.comwrote:

 wats d problem in my display()




 #includeiostream
 #includemalloc.h
 #include string.h

 using namespace std;
 struct node
 {
 char *name;
 struct node *next;
 };
 typedef struct node Node;

 void createList(Node **head )
 {
 char str[20];
 char *p;
 coutEnter a String:   ;
 gets (str) ;
 p = str;
 if((strlen(p))2)
  return;
 Node *temp=*head;
 Node *newnode=(Node*)malloc(sizeof(Node));
 newnode-name=p;
 newnode-next=NULL;
 if(!temp)
 *head = newnode;
 else
 {
 while(temp-next)
temp = temp-next;
 temp-next = newnode;
 }
 createList(head);
 }
 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }
 int main()
 {
 Node *head=NULL;
 while(1)
 {
 cout\n\t\tMENU\n;
 cout0   : To exit.\n;
 cout1   : To create a linear link list.\n;
 cout2   : To display the list.\n;
 char choice;
 choice = getchar();
 getchar();
 if(choice=='0')
 break;
 switch(choice)
 {
 case '1':
 createList(head );
 break;
  case '2':
 display(head);
 break;
 default:
 coutEnter valid choice.;
}
 }
 system(pause);
 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Thanks  Regards
Ram Narayan Das
mob: +91 9177711195

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



Re: [algogeeks] linked list

2010-08-19 Thread vineeth mohan
void display(Node *head)
{
 cout\n;
 for( ; head ; head=head-next)
cout\thead-name;
 cout\n;
}


when head reaches last node
condition head is true , then head will become head-next which is null ,
and it will try to print the name field from of a null value which is error

On Wed, Aug 18, 2010 at 10:53 PM, Raj Jagvanshi raj.jagvan...@gmail.comwrote:

 wats d problem in my display()




 #includeiostream
 #includemalloc.h
 #include string.h

 using namespace std;
 struct node
 {
 char *name;
 struct node *next;
 };
 typedef struct node Node;

 void createList(Node **head )
 {
 char str[20];
 char *p;
 coutEnter a String:   ;
 gets (str) ;
 p = str;
 if((strlen(p))2)
  return;
 Node *temp=*head;
 Node *newnode=(Node*)malloc(sizeof(Node));
 newnode-name=p;
 newnode-next=NULL;
 if(!temp)
 *head = newnode;
 else
 {
 while(temp-next)
temp = temp-next;
 temp-next = newnode;
 }
 createList(head);
 }
 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }
 int main()
 {
 Node *head=NULL;
 while(1)
 {
 cout\n\t\tMENU\n;
 cout0   : To exit.\n;
 cout1   : To create a linear link list.\n;
 cout2   : To display the list.\n;
 char choice;
 choice = getchar();
 getchar();
 if(choice=='0')
 break;
 switch(choice)
 {
 case '1':
 createList(head );
 break;
  case '2':
 display(head);
 break;
 default:
 coutEnter valid choice.;
}
 }
 system(pause);
 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list

2010-08-19 Thread ram das
no it head to head-next at the end of for loop block not at the beginning.
try out this
for (int t=0;t5;t++)
cout\nt;

On Thu, Aug 19, 2010 at 5:22 PM, vineeth mohan vm.vineethmo...@gmail.comwrote:

 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }


 when head reaches last node
 condition head is true , then head will become head-next which is null ,
 and it will try to print the name field from of a null value which is error


 On Wed, Aug 18, 2010 at 10:53 PM, Raj Jagvanshi 
 raj.jagvan...@gmail.comwrote:

 wats d problem in my display()




 #includeiostream
 #includemalloc.h
 #include string.h

 using namespace std;
 struct node
 {
 char *name;
 struct node *next;
 };
 typedef struct node Node;

 void createList(Node **head )
 {
 char str[20];
 char *p;
 coutEnter a String:   ;
 gets (str) ;
 p = str;
 if((strlen(p))2)
  return;
 Node *temp=*head;
 Node *newnode=(Node*)malloc(sizeof(Node));
 newnode-name=p;
 newnode-next=NULL;
 if(!temp)
 *head = newnode;
 else
 {
 while(temp-next)
temp = temp-next;
 temp-next = newnode;
 }
 createList(head);
 }
 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }
 int main()
 {
 Node *head=NULL;
 while(1)
 {
 cout\n\t\tMENU\n;
 cout0   : To exit.\n;
 cout1   : To create a linear link list.\n;
 cout2   : To display the list.\n;
 char choice;
 choice = getchar();
 getchar();
 if(choice=='0')
 break;
 switch(choice)
 {
 case '1':
 createList(head );
 break;
  case '2':
 display(head);
 break;
 default:
 coutEnter valid choice.;
}
 }
 system(pause);
 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




-- 
Thanks  Regards
Ram Narayan Das
mob: +91 9177711195

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



Re: [algogeeks] linked list

2010-08-19 Thread Raj Jagvanshi
my display function print garbage value from begining

On Thu, Aug 19, 2010 at 4:23 PM, ram das ramnaraya...@gmail.com wrote:

 make declaration of char str[20] to  char
 *str=(char*)malloc(20*sizeof(char));
 and it will work .

 On Wed, Aug 18, 2010 at 11:23 PM, Raj Jagvanshi 
 raj.jagvan...@gmail.comwrote:

 wats d problem in my display()




 #includeiostream
 #includemalloc.h
 #include string.h

 using namespace std;
 struct node
 {
 char *name;
 struct node *next;
 };
 typedef struct node Node;

 void createList(Node **head )
 {
 char str[20];
 char *p;
 coutEnter a String:   ;
 gets (str) ;
 p = str;
 if((strlen(p))2)
  return;
 Node *temp=*head;
 Node *newnode=(Node*)malloc(sizeof(Node));
 newnode-name=p;
 newnode-next=NULL;
 if(!temp)
 *head = newnode;
 else
 {
 while(temp-next)
temp = temp-next;
 temp-next = newnode;
 }
 createList(head);
 }
 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }
 int main()
 {
 Node *head=NULL;
 while(1)
 {
 cout\n\t\tMENU\n;
 cout0   : To exit.\n;
 cout1   : To create a linear link list.\n;
 cout2   : To display the list.\n;
 char choice;
 choice = getchar();
 getchar();
 if(choice=='0')
 break;
 switch(choice)
 {
 case '1':
 createList(head );
 break;
  case '2':
 display(head);
 break;
 default:
 coutEnter valid choice.;
}
 }
 system(pause);
 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.




 --
 Thanks  Regards
 Ram Narayan Das
 mob: +91 9177711195

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list

2010-08-19 Thread Raj Jagvanshi
my display function print garbage value from begining

On Thu, Aug 19, 2010 at 5:22 PM, vineeth mohan vm.vineethmo...@gmail.comwrote:

 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }


 when head reaches last node
 condition head is true , then head will become head-next which is null ,
 and it will try to print the name field from of a null value which is error

 On Wed, Aug 18, 2010 at 10:53 PM, Raj Jagvanshi 
 raj.jagvan...@gmail.comwrote:

 wats d problem in my display()




 #includeiostream
 #includemalloc.h
 #include string.h

 using namespace std;
 struct node
 {
 char *name;
 struct node *next;
 };
 typedef struct node Node;

 void createList(Node **head )
 {
 char str[20];
 char *p;
 coutEnter a String:   ;
 gets (str) ;
 p = str;
 if((strlen(p))2)
  return;
 Node *temp=*head;
 Node *newnode=(Node*)malloc(sizeof(Node));
 newnode-name=p;
 newnode-next=NULL;
 if(!temp)
 *head = newnode;
 else
 {
 while(temp-next)
temp = temp-next;
 temp-next = newnode;
 }
 createList(head);
 }
 void display(Node *head)
 {
  cout\n;
  for( ; head ; head=head-next)
 cout\thead-name;
  cout\n;
 }
 int main()
 {
 Node *head=NULL;
 while(1)
 {
 cout\n\t\tMENU\n;
 cout0   : To exit.\n;
 cout1   : To create a linear link list.\n;
 cout2   : To display the list.\n;
 char choice;
 choice = getchar();
 getchar();
 if(choice=='0')
 break;
 switch(choice)
 {
 case '1':
 createList(head );
 break;
  case '2':
 display(head);
 break;
 default:
 coutEnter valid choice.;
}
 }
 system(pause);
 return 0;
 }

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] Linked List

2010-08-18 Thread bittu
can any one tell me  in the below post

struct node
{
int info;
struct node *next;
};
typedef struct node NODE;  1. why typedef used  whats d
benifet of doing this
NODE *start;
void createmptylist(NODE **start) 2. why Node **start used instead we
can also use Node *start  get same re.
{
*start=(NODE *)NULL;
}

why typede

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



Re: [algogeeks] linked list

2010-06-24 Thread Raj N
Keep a pointer list1 at the beginning of one of the lists, and call the
function below on the other list.
int reverseCheck(NODE *p)
{
  list2=p;
 if(list2-next==NULL)
  return;
  reverseCheck(list2-next);
  if(list2-next-data==list1-data)
  list1=list1-next;
  else
 flag=0;
 return flag;
}



On Wed, Jun 23, 2010 at 6:00 PM, divya jain sweetdivya@gmail.comwrote:

 if we dont want to change original list..
 is there ny efficient method for that?


 On 23 June 2010 06:49, ANUJ KUMAR kumar.anuj...@gmail.com wrote:

 reverse one of the linked lists in O(n) time and then see if the
 resulting one is same as the other one

 On Wed, Jun 23, 2010 at 1:56 AM, divya sweetdivya@gmail.com wrote:
  Two link lists are given ...check if one is reverse of other. Do it
  without using extra space.
 
  --
  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list

2010-06-23 Thread divya jain
if we dont want to change original list..
is there ny efficient method for that?

On 23 June 2010 06:49, ANUJ KUMAR kumar.anuj...@gmail.com wrote:

 reverse one of the linked lists in O(n) time and then see if the
 resulting one is same as the other one

 On Wed, Jun 23, 2010 at 1:56 AM, divya sweetdivya@gmail.com wrote:
  Two link lists are given ...check if one is reverse of other. Do it
  without using extra space.
 
  --
  You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] linked list

2010-06-23 Thread Amit Mittal
this is same as finding palindrome in a given linked list..
it may help
http://geeksforgeeks.org/?p=1072

On Wed, Jun 23, 2010 at 6:00 PM, divya jain sweetdivya@gmail.comwrote:

 if we dont want to change original list..
 is there ny efficient method for that?


 On 23 June 2010 06:49, ANUJ KUMAR kumar.anuj...@gmail.com wrote:

 reverse one of the linked lists in O(n) time and then see if the
 resulting one is same as the other one

 On Wed, Jun 23, 2010 at 1:56 AM, divya sweetdivya@gmail.com wrote:
  Two link lists are given ...check if one is reverse of other. Do it
  without using extra space.
 
  --
  You received this message because you are subscribed to the Google
 Groups Algorithm Geeks group.
  To post to this group, send email to algoge...@googlegroups.com.
  To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
  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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.comalgogeeks%2bunsubscr...@googlegroups.com
 .
 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 algoge...@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



[algogeeks] linked list

2010-06-22 Thread divya
Two link lists are given ...check if one is reverse of other. Do it
without using extra space.

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



[algogeeks] linked list questions

2009-08-12 Thread varun bhatia
1. Given a single link list with one info part containing single character
and a link. Check whether the link list is a palindrome or not.
The algo should run in Linear time only. You can't use any array or string
to store the string of link-list.

2. You are given a Double Link List with one pointer of each node pointing
to the next node just like in a single link list. The second pointer however
CAN point to any node in the list and not just the previous node.
Now write a program in O(n) time to duplicate this list. That is, write a
program which will create a copy of this list.
-- 
Regards,

Varun Bhatia
MCA
Department of Computer Science,
University of Delhi,
Delhi - 110007

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] linked list corruption

2008-06-23 Thread zee

what does linked list corruption mean ..

how to detect linked list corruption 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] linked list

2008-06-10 Thread zee99 . 99

is there any algo that can search a linked list in less than O(n) time 

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] linked list search

2008-06-06 Thread zee 99
what is the most efficient way to search a linked list in sorted order ?

is there an algorithm that performs faster than O(n)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---



[algogeeks] linked list search

2008-06-06 Thread zee 99
what is the most efficient way to search a linked list in sorted order ?

is there an algorithm that performs faster than O(n)

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/algogeeks
-~--~~~~--~~--~--~---