SlideShare a Scribd company logo
1 of 2
Download to read offline
What is wrong with the following definition of headInsert?
struct Node {
int item;
Node* link; };
typedef Node* NodePtr;
void headInsert(NodePtr& head, int data) {
NodePtr tmp = new Node;
tmp->item = data;
head->next = tmp;
tmp->next = head->next;
}
NodePtr head; headInsert(head, 4);
A. tmp should be declared to be a Node not a NodePtr.
B. head->next is pointing to NULL.
C. Nothing is wrong.
D. If there were any nodes following head they are now lost.
Solution
B. head->next is pointing to NULL.
Because of which tmp is not getting stored in the linked list
Correct Code:
struct Node
{
int item;
Node* link;
};
typedef Node* NodePtr;
void headInsert(NodePtr& head, int data)
{
NodePtr tmp = new Node;
tmp->item = data;
// next of tmp should be assigned head
tmp->link = head;
head = tmp;
}

More Related Content

More from deepaarora22

A mutant strain of E. coli is found that produces both beta-galactos.pdf
A mutant strain of E. coli is found that produces both beta-galactos.pdfA mutant strain of E. coli is found that produces both beta-galactos.pdf
A mutant strain of E. coli is found that produces both beta-galactos.pdf
deepaarora22
 
What are the difference between the testes of a frog and a rat in te.pdf
What are the difference between the testes of a frog and a rat in te.pdfWhat are the difference between the testes of a frog and a rat in te.pdf
What are the difference between the testes of a frog and a rat in te.pdf
deepaarora22
 
What are the basic differences and commonalties between Structured An.pdf
What are the basic differences and commonalties between Structured An.pdfWhat are the basic differences and commonalties between Structured An.pdf
What are the basic differences and commonalties between Structured An.pdf
deepaarora22
 
1. My anatomy I am quite small as compared to many microorganisms. M.pdf
1. My anatomy I am quite small as compared to many microorganisms. M.pdf1. My anatomy I am quite small as compared to many microorganisms. M.pdf
1. My anatomy I am quite small as compared to many microorganisms. M.pdf
deepaarora22
 
Normalization work as through a series of stages called normal forms .pdf
Normalization work as through a series of stages called normal forms .pdfNormalization work as through a series of stages called normal forms .pdf
Normalization work as through a series of stages called normal forms .pdf
deepaarora22
 

More from deepaarora22 (20)

A mutant strain of E. coli is found that produces both beta-galactos.pdf
A mutant strain of E. coli is found that produces both beta-galactos.pdfA mutant strain of E. coli is found that produces both beta-galactos.pdf
A mutant strain of E. coli is found that produces both beta-galactos.pdf
 
An unknown individual launches a series of attacks against the Web s.pdf
An unknown individual launches a series of attacks against the Web s.pdfAn unknown individual launches a series of attacks against the Web s.pdf
An unknown individual launches a series of attacks against the Web s.pdf
 
Youve completed an interrupted mating experiment in E. coli, the l.pdf
Youve completed an interrupted mating experiment in E. coli, the  l.pdfYouve completed an interrupted mating experiment in E. coli, the  l.pdf
Youve completed an interrupted mating experiment in E. coli, the l.pdf
 
Write the following Scheme functions in JavaSolutionimport ja.pdf
Write the following Scheme functions in JavaSolutionimport ja.pdfWrite the following Scheme functions in JavaSolutionimport ja.pdf
Write the following Scheme functions in JavaSolutionimport ja.pdf
 
Write a C program to enter a first name, middle name and last name i.pdf
Write a C program to enter a first name, middle name and last name i.pdfWrite a C program to enter a first name, middle name and last name i.pdf
Write a C program to enter a first name, middle name and last name i.pdf
 
Why do the soft technologies open more opportunities for women To w.pdf
Why do the soft technologies open more opportunities for women To w.pdfWhy do the soft technologies open more opportunities for women To w.pdf
Why do the soft technologies open more opportunities for women To w.pdf
 
What are the difference between the testes of a frog and a rat in te.pdf
What are the difference between the testes of a frog and a rat in te.pdfWhat are the difference between the testes of a frog and a rat in te.pdf
What are the difference between the testes of a frog and a rat in te.pdf
 
Which of the following occurs with disruptive selectiona. Natural .pdf
Which of the following occurs with disruptive selectiona. Natural .pdfWhich of the following occurs with disruptive selectiona. Natural .pdf
Which of the following occurs with disruptive selectiona. Natural .pdf
 
When comparing replicate populations of plants that are grown in the .pdf
When comparing replicate populations of plants that are grown in the .pdfWhen comparing replicate populations of plants that are grown in the .pdf
When comparing replicate populations of plants that are grown in the .pdf
 
What is the BEST way to determine if there are any gaps in your thes.pdf
What is the BEST way to determine if there are any gaps in your thes.pdfWhat is the BEST way to determine if there are any gaps in your thes.pdf
What is the BEST way to determine if there are any gaps in your thes.pdf
 
What are two specialized epidermal cells and what do they do for the.pdf
What are two specialized epidermal cells and what do they do for the.pdfWhat are two specialized epidermal cells and what do they do for the.pdf
What are two specialized epidermal cells and what do they do for the.pdf
 
What are the basic differences and commonalties between Structured An.pdf
What are the basic differences and commonalties between Structured An.pdfWhat are the basic differences and commonalties between Structured An.pdf
What are the basic differences and commonalties between Structured An.pdf
 
Use the following word bank to complete the number 51-100 This struc.pdf
Use the following word bank to complete the number 51-100  This struc.pdfUse the following word bank to complete the number 51-100  This struc.pdf
Use the following word bank to complete the number 51-100 This struc.pdf
 
The nucleus is something we are debating on Celias thread too. Alt.pdf
The nucleus is something we are debating on Celias thread too. Alt.pdfThe nucleus is something we are debating on Celias thread too. Alt.pdf
The nucleus is something we are debating on Celias thread too. Alt.pdf
 
2. A one-period rate of return from an investment can be measured as.pdf
2. A one-period rate of return from an investment can be measured as.pdf2. A one-period rate of return from an investment can be measured as.pdf
2. A one-period rate of return from an investment can be measured as.pdf
 
19. Photosynthetic organisms are found in the Domain Eukarya as well .pdf
19. Photosynthetic organisms are found in the Domain Eukarya as well .pdf19. Photosynthetic organisms are found in the Domain Eukarya as well .pdf
19. Photosynthetic organisms are found in the Domain Eukarya as well .pdf
 
Qualitative methods tend to have those characteristics. Establis.pdf
Qualitative methods tend to have those characteristics.  Establis.pdfQualitative methods tend to have those characteristics.  Establis.pdf
Qualitative methods tend to have those characteristics. Establis.pdf
 
onchange, onclick and onkeyup, are some examples of ...A. Tags B. .pdf
onchange, onclick and onkeyup, are some examples of ...A. Tags B. .pdfonchange, onclick and onkeyup, are some examples of ...A. Tags B. .pdf
onchange, onclick and onkeyup, are some examples of ...A. Tags B. .pdf
 
1. My anatomy I am quite small as compared to many microorganisms. M.pdf
1. My anatomy I am quite small as compared to many microorganisms. M.pdf1. My anatomy I am quite small as compared to many microorganisms. M.pdf
1. My anatomy I am quite small as compared to many microorganisms. M.pdf
 
Normalization work as through a series of stages called normal forms .pdf
Normalization work as through a series of stages called normal forms .pdfNormalization work as through a series of stages called normal forms .pdf
Normalization work as through a series of stages called normal forms .pdf
 

Recently uploaded

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 

What is wrong with the following definition of headInsertstruct N.pdf

  • 1. What is wrong with the following definition of headInsert? struct Node { int item; Node* link; }; typedef Node* NodePtr; void headInsert(NodePtr& head, int data) { NodePtr tmp = new Node; tmp->item = data; head->next = tmp; tmp->next = head->next; } NodePtr head; headInsert(head, 4); A. tmp should be declared to be a Node not a NodePtr. B. head->next is pointing to NULL. C. Nothing is wrong. D. If there were any nodes following head they are now lost. Solution B. head->next is pointing to NULL. Because of which tmp is not getting stored in the linked list Correct Code: struct Node { int item; Node* link; }; typedef Node* NodePtr; void headInsert(NodePtr& head, int data) { NodePtr tmp = new Node; tmp->item = data; // next of tmp should be assigned head tmp->link = head;