struct node
{
int data;
node* next;
};
node* head=NULL;
void deleteend()
{
node *ptr,*prev;
if(head==NULL) //empty list
cout<<"list empty";
else
if(head->next==NULL) //only one node in list
{
ptr=head;
head=NULL;
free(ptr);
}
else{ //more than one node
ptr=head;
while(ptr->next!=NULL)
{
prev=ptr;
ptr=ptr->next;
}
prev->next=NULL;
free(ptr);
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter