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