Re: [algogeeks] Linked list using void pointer
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
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
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
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.