linked list query

write a function that inserts a node at the beginning of the linked list and a function that deletes the first node of the linked list.

please do code in c or c++
I've already done that some time ago.

please do read http://www.cplusplus.com/articles/how_to_ask/
This is actually my first post, but I think i could be a bit of some help.
I wrote this code in c++ format.

#include<iostream.h>
#include<stdlib.h>

typedef class node * pnode;
class node
{private:
int data;
pnode next;
public:
node(){next=NULL;}
friend class list;
};


class list
{ private:
pnode first;
public:
list(){first=NULL;}
void insert_front(int );
void remove_front();
};

void list::insert_front(int element)
{ pnode p=new node;
p->data=element;
p->next=first;
first=p;
}

void list::remove_front()
{ pnode temp=first;
first=first->next;
delete temp;
}


Topic archived. No new replies allowed.