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

> 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:
> LNode<T> *head;
> LNode<T> *tail;
> public:
> LList()
> {
> head=tail=NULL;
>  }
>
> void push_back(T pData)
> {
>  if(head==NULL)
> {
> head=tail=new LNode<T>(pData,NULL);
>  return;
> }
> tail->next=new LNode<T>(pData,NULL);
>  tail=tail->next;
> }
> void push_front(T pData)
>  {
> if(head==NULL)
> {
>  head=tail=new LNode<T>(pData,NULL);
> return;
> }
>  LNode<T> *nnode=new LNode<T>(pData,head);
> head=nnode;
> }
>  void Print()
> {
> LNode<int> *cur=head;
>  while(cur)
> {
> cout<<cur->data<<',';
>  cur=cur->next;
> }
> cout << endl;
>  }
> void Reverse()
> {
>  LNode<T> *cur=head;
> LNode<T> *prev=NULL;
> LNode<T> *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.com>wrote:
>
>> 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.com<gvib...@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.

Reply via email to