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

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

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,

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,

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

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), ...,

[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 =

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

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

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,

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

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

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

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

[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

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,

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

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,

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

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

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

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) {

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 +

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,

[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

[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

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

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.

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

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

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

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

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

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

[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;

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;

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

[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

[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 ?

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

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

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

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

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

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

[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

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

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

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

[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

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

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

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

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

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

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

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

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

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 --

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

[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

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

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;

[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

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

[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

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

[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

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

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

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

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) ;

[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)

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;

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

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)

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

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

[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. {

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

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

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

[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,

[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

[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] 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

[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

[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