SlideShare a Scribd company logo
Discuss about Header Node? And also write a program for unordered single linked list and
linked implementation of QUEUE?
Solution
Header node:
Sometimes it is desire to keep an extra node at the front of a List. Such a node doesn’t represent
an item in the List and is called a Header Node or a List Header. The Information field of such
Header node might be unused but the Next field maintains the first node address. More often the
information of such a node could be used to keep Global Information about the Entire List.
One of the applications of Header node is the information portion of the Header node contains
the number of nodes (not including Header) in the List. In this Structure the Header must be
adjusted the total number of nodes when we apply addition or deletion operation on the List. We
can directly obtained the total number of nodes without traversing the entire List.
By using this application, we can develop Data Structure Stack easily. Since Header node
information field maintains the number of elements that the Stack contains.
Another application is we can simply develop the Data Structure Queue. Until now, two external
pointers, Front & Rear, were necessary for a List to represent a Queue. However, now only a
single external pointer is sufficient to maintain a Queue that is Head node. Because the Header
node next field behave like a Front and information field of Header node maintains last node
address so that it is behave like a Rear .
Another possibility for the use of the information portion of a List Header is as a pointer
to a Curr node in the List during a traversal process. This would be eliminate the node for an
external pointer during traversal.
#include
#include
#include
#include
struct node
{
char info;
struct node *next;
};
typedef struct node sl;
void display(sl *);
sl * create(sl *root)
{
sl *curr,*new;
char val;
printf(" Enter $ to STOP --- Otherwise Continue : ");
fflush(stdin);
scanf("%c",&val);
while(val != '$')
{
new=(sl *) malloc(sizeof(sl));
new->info = val;
new->next = NULL;
if(root == NULL)
root = new;
else
{
curr = root;
while( curr->next != NULL )
curr = curr->next;
curr->next = new;
}
printf(" Enter $ to STOP --- Otherwise Continue : ");
fflush(stdin);
scanf("%c",&val);
}
printf(" The Created Linked List Is  ");
display(root);
return root;
}
sl * delete(sl *root,char val)
{
sl *temp,*curr,*rear;
curr = root;
rear = NULL;
while( curr != NULL && val != curr->info )
{
rear = curr;
curr = curr->next;
}
if(curr == NULL)
{
if( rear == NULL)
{
printf(" Linked List is Empty");
printf(" Deletion is not Possible ");
}
else
{
printf(" deleted Node does not exist in List");
printf(" Deletion is not Possible ");
}
}
else
{
if( rear == NULL)
{
temp = root;
root = root->next;
}
else
{
temp = curr;
rear->next = curr->next;
}
printf(" Node is deleted ");
printf(" Deleted Node information is %c",temp->info);
free(temp);
}
display(root);
return root;
}
sl * insert(sl *root,char val)
{
sl *curr,*new;
new=(sl *) malloc(sizeof(sl));
new->info = val;
new->next = NULL;
if(root == NULL)
root = new;
else
{
curr = root;
while( curr->next != NULL )
curr = curr->next;
curr->next = new;
}
return root;
}
void display(sl *start)
{
printf(" ROOT-> ");
while(start != NULL )
{
printf("%c -> ",start->info);
start =start->next;
}
printf("NULL  ");
getch();
}
char menu()
{
char ch;
clrscr();
gotoxy(33,2); printf("MAIN MENU");
gotoxy(25,6); printf("Creation C");
gotoxy(25,8); printf("Insertion I");
gotoxy(25,10);printf("Removing R");
gotoxy(25,12);printf("Display D");
gotoxy(25,14);printf("Quit Q");
gotoxy(10,30);printf(" Enter Choice : ");
fflush(stdin);
scanf("%c",&ch);
return(ch);
}
main()
{
sl *insert(sl *,char),*delete(sl *,char),*create(sl *);
sl *root=NULL;
char item;
char choice;
char menu();
while( ( choice=menu() ) != 'Q' || ( choice != 'q') )
{
switch(choice)
{
case 'c':
case 'C': root = NULL;
root = create(root);
break;
case 'i':
case 'I': printf("Enter Character Item to be Inserted : ");
fflush(stdin);
scanf("%c",&item);
root = insert(root,item);
break;
case 'd':
case 'D': printf("The Current Linked List is : ");
display(root);
getch();
break;
case 'r':
case 'R': printf("Enter the Item wich you want to be Remove :");
fflush(stdin);
scanf("%c",&item);
root = delete(root,item);
break;
case 'q':
case 'Q': return;
}
}
}

More Related Content

PDF
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
PPTX
Implemention of Linked list concept in Data Structures
PPT
Unit7 C
PDF
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
DOCX
What is Linked List in C.docx
PPTX
Linked list
PDF
For this homework, you will write a program to create and manipulate.pdf
PPTX
Data structure
^^^Q2. Discuss about Header Node    And also write a program fo.pdf
Implemention of Linked list concept in Data Structures
Unit7 C
C++ Program It is only 1 rotation. Up-rotation of a stack. Write a.pdf
What is Linked List in C.docx
Linked list
For this homework, you will write a program to create and manipulate.pdf
Data structure

Similar to Discuss about Header Node And also write a program for unordered si.pdf (20)

PPTX
Stack and Queue
PDF
Use the singly linked list class introduced in the lab to implement .pdf
PDF
File name a2.cppTaskFor this assignment, you are required to ei.pdf
PPT
Linked list1.ppt
PDF
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
PDF
Data structure
PPTX
linkedlist.pptx
PPTX
Linear data structure concepts
PPTX
Adt of lists
PDF
TutorialII_Updated____niceupdateprogram.pdf
PPTX
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
PDF
Unit - 2.pdf
PPT
Unit ii(dsc++)
PPT
DS Unit 2.ppt
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
PDF
How to delete one specific node in linked list in CThanksSolu.pdf
PDF
Program In C You are required to write an interactive C program that.pdf
PPT
Introduction to Data structures and Trees.ppt
PPTX
Data Structures and Agorithm: DS 04 Linked List.pptx
PPTX
Linked list
Stack and Queue
Use the singly linked list class introduced in the lab to implement .pdf
File name a2.cppTaskFor this assignment, you are required to ei.pdf
Linked list1.ppt
in C++ , Design a linked list class named IntegerList to hold a seri.pdf
Data structure
linkedlist.pptx
Linear data structure concepts
Adt of lists
TutorialII_Updated____niceupdateprogram.pdf
UNIT I LINEAR DATA STRUCTURES – LIST .pptx
Unit - 2.pdf
Unit ii(dsc++)
DS Unit 2.ppt
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
How to delete one specific node in linked list in CThanksSolu.pdf
Program In C You are required to write an interactive C program that.pdf
Introduction to Data structures and Trees.ppt
Data Structures and Agorithm: DS 04 Linked List.pptx
Linked list
Ad

More from eyevision3 (20)

PDF
According to Bacon, the objets of scientific inquiry were a phenomen.pdf
PDF
A--The new generation of robotics    a) Considering that the new g.pdf
PDF
a).write the differences between Bryophytes and pterophytes (ferns)..pdf
PDF
Which best describes the following A symbol, word, name, sound, or .pdf
PDF
What are the types of diffusion and describe the two atomic mechanism.pdf
PDF
3. Four species of ground beetle in the genus Carabus are known to be.pdf
PDF
Network service providers retain records for various lengths of time.pdf
PDF
Please use your own words, do not just copy and paste !!!For Selec.pdf
PDF
My sister, Lilly, and I used to have a great time playing with jelly.pdf
PDF
4. Why are women more prone to urinary tract infectionsSolution.pdf
PDF
13 What type of joint is present at ll, the Hinge Ball and Sliding Fi.pdf
PDF
Sort animals below into subsets. There are five. State reason for.pdf
PDF
Protons are unable to cross the lipid bilayer becausea) the lipid.pdf
PDF
More practice with four coins Make a neat table that lists all the s.pdf
PDF
Question 10 (1.2 points) d What helps explain the popularity of mutua.pdf
PDF
overall, what is the net trend of NPP due to climate change Moving t.pdf
PDF
1. Substance’s Effect Increases the number of free hydrogen ions or.pdf
PDF
1. What are three functions of an operating system2. What are t.pdf
PDF
Most bacteria that cause diseases in humans have a temperature optim.pdf
PDF
Need help understanding how to solve D. and E. Please show how y.pdf
According to Bacon, the objets of scientific inquiry were a phenomen.pdf
A--The new generation of robotics    a) Considering that the new g.pdf
a).write the differences between Bryophytes and pterophytes (ferns)..pdf
Which best describes the following A symbol, word, name, sound, or .pdf
What are the types of diffusion and describe the two atomic mechanism.pdf
3. Four species of ground beetle in the genus Carabus are known to be.pdf
Network service providers retain records for various lengths of time.pdf
Please use your own words, do not just copy and paste !!!For Selec.pdf
My sister, Lilly, and I used to have a great time playing with jelly.pdf
4. Why are women more prone to urinary tract infectionsSolution.pdf
13 What type of joint is present at ll, the Hinge Ball and Sliding Fi.pdf
Sort animals below into subsets. There are five. State reason for.pdf
Protons are unable to cross the lipid bilayer becausea) the lipid.pdf
More practice with four coins Make a neat table that lists all the s.pdf
Question 10 (1.2 points) d What helps explain the popularity of mutua.pdf
overall, what is the net trend of NPP due to climate change Moving t.pdf
1. Substance’s Effect Increases the number of free hydrogen ions or.pdf
1. What are three functions of an operating system2. What are t.pdf
Most bacteria that cause diseases in humans have a temperature optim.pdf
Need help understanding how to solve D. and E. Please show how y.pdf
Ad

Recently uploaded (20)

PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
Cell Structure & Organelles in detailed.
PDF
Microbial disease of the cardiovascular and lymphatic systems
PDF
Computing-Curriculum for Schools in Ghana
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Lesson notes of climatology university.
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Institutional Correction lecture only . . .
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
master seminar digital applications in india
PDF
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Cell Structure & Organelles in detailed.
Microbial disease of the cardiovascular and lymphatic systems
Computing-Curriculum for Schools in Ghana
Anesthesia in Laparoscopic Surgery in India
Lesson notes of climatology university.
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
2.FourierTransform-ShortQuestionswithAnswers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
202450812 BayCHI UCSC-SV 20250812 v17.pptx
Complications of Minimal Access Surgery at WLH
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
A systematic review of self-coping strategies used by university students to ...
Institutional Correction lecture only . . .
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Microbial diseases, their pathogenesis and prophylaxis
master seminar digital applications in india
OBE - B.A.(HON'S) IN INTERIOR ARCHITECTURE -Ar.MOHIUDDIN.pdf

Discuss about Header Node And also write a program for unordered si.pdf

  • 1. Discuss about Header Node? And also write a program for unordered single linked list and linked implementation of QUEUE? Solution Header node: Sometimes it is desire to keep an extra node at the front of a List. Such a node doesn’t represent an item in the List and is called a Header Node or a List Header. The Information field of such Header node might be unused but the Next field maintains the first node address. More often the information of such a node could be used to keep Global Information about the Entire List. One of the applications of Header node is the information portion of the Header node contains the number of nodes (not including Header) in the List. In this Structure the Header must be adjusted the total number of nodes when we apply addition or deletion operation on the List. We can directly obtained the total number of nodes without traversing the entire List. By using this application, we can develop Data Structure Stack easily. Since Header node information field maintains the number of elements that the Stack contains. Another application is we can simply develop the Data Structure Queue. Until now, two external pointers, Front & Rear, were necessary for a List to represent a Queue. However, now only a single external pointer is sufficient to maintain a Queue that is Head node. Because the Header node next field behave like a Front and information field of Header node maintains last node address so that it is behave like a Rear . Another possibility for the use of the information portion of a List Header is as a pointer to a Curr node in the List during a traversal process. This would be eliminate the node for an external pointer during traversal. #include #include #include #include struct node { char info; struct node *next; }; typedef struct node sl; void display(sl *);
  • 2. sl * create(sl *root) { sl *curr,*new; char val; printf(" Enter $ to STOP --- Otherwise Continue : "); fflush(stdin); scanf("%c",&val); while(val != '$') { new=(sl *) malloc(sizeof(sl)); new->info = val; new->next = NULL; if(root == NULL) root = new; else { curr = root; while( curr->next != NULL ) curr = curr->next; curr->next = new; } printf(" Enter $ to STOP --- Otherwise Continue : "); fflush(stdin); scanf("%c",&val); } printf(" The Created Linked List Is "); display(root); return root; } sl * delete(sl *root,char val) { sl *temp,*curr,*rear; curr = root; rear = NULL; while( curr != NULL && val != curr->info ) {
  • 3. rear = curr; curr = curr->next; } if(curr == NULL) { if( rear == NULL) { printf(" Linked List is Empty"); printf(" Deletion is not Possible "); } else { printf(" deleted Node does not exist in List"); printf(" Deletion is not Possible "); } } else { if( rear == NULL) { temp = root; root = root->next; } else { temp = curr; rear->next = curr->next; } printf(" Node is deleted "); printf(" Deleted Node information is %c",temp->info); free(temp); } display(root); return root; } sl * insert(sl *root,char val)
  • 4. { sl *curr,*new; new=(sl *) malloc(sizeof(sl)); new->info = val; new->next = NULL; if(root == NULL) root = new; else { curr = root; while( curr->next != NULL ) curr = curr->next; curr->next = new; } return root; } void display(sl *start) { printf(" ROOT-> "); while(start != NULL ) { printf("%c -> ",start->info); start =start->next; } printf("NULL "); getch(); } char menu() { char ch; clrscr(); gotoxy(33,2); printf("MAIN MENU"); gotoxy(25,6); printf("Creation C"); gotoxy(25,8); printf("Insertion I"); gotoxy(25,10);printf("Removing R"); gotoxy(25,12);printf("Display D");
  • 5. gotoxy(25,14);printf("Quit Q"); gotoxy(10,30);printf(" Enter Choice : "); fflush(stdin); scanf("%c",&ch); return(ch); } main() { sl *insert(sl *,char),*delete(sl *,char),*create(sl *); sl *root=NULL; char item; char choice; char menu(); while( ( choice=menu() ) != 'Q' || ( choice != 'q') ) { switch(choice) { case 'c': case 'C': root = NULL; root = create(root); break; case 'i': case 'I': printf("Enter Character Item to be Inserted : "); fflush(stdin); scanf("%c",&item); root = insert(root,item); break; case 'd': case 'D': printf("The Current Linked List is : "); display(root); getch(); break; case 'r': case 'R': printf("Enter the Item wich you want to be Remove :"); fflush(stdin); scanf("%c",&item);
  • 6. root = delete(root,item); break; case 'q': case 'Q': return; } } }