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++
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;
}