Algorithm
INPUT: HEADER IS A POINTER TO THE HEADER NODE OF THE LINKEDLIST
OUTPUT: LINKEDLIST WITHOUT FIRST ELEMENT
DATA STRUCTURE: SINGLY LINKEDLIST
STEP 1: PTR=HEADER->LINK
STEP 2: HEADER->LINK=PTR->LINK
STEP 3: FREE(PTR)
Code
#include <stdio.h>
#include <stdlib.h>
int getnode(int);
void display();
void newnode();
int x;
struct node{
int data;
struct node *link;
};
struct node *prev,*head,*news,*p;
struct node *header;
int main(){
int n;
printf("ENTER THE LIMIT ");
scanf("%d",&n);
getnode(n);
return 0;}
void display(struct node *head){
struct node *ptr;
ptr=head->link;
while(ptr!=header){
printf("%d ",ptr->data);
ptr=ptr->link;} }
void newnode(){
struct node* ptr;
ptr=header->link;
header->link=ptr->link;
free(ptr);
}
int getnode(int n){
header=malloc(sizeof(struct node));
head=NULL;
for(int i=0;i<n;i++){
p=malloc(sizeof(struct node));
scanf("%d",&p->data);
p->link=NULL;
if(head==NULL)
head=p;
else
prev->link=p;
prev=p;
}header->link=head;
p->link=header;
display(header);
printf("list after deletion ");
newnode();
display(header);
return 0;}
Output
user@computer$ : ENTER THE LIMIT 5
1
2
3
4
5
1 2 3 4 5 list after deletion 2 3 4 5