Question: #include #include using namespace std; struct node { int data; node * next; } ; void insertN ( node * &head, node * &displayPtr, int

#include
#include
using namespace std;
struct node
{
int data;
node
*
next;
}
;
void insertN
(
node
*
&head, node
*
&displayPtr, int data
)
{
node
*
pnode;
pnode
=
new node;
if
(
pnode
=
=
NULL
)
{
cout
<
<
"Unable to locate node"
<
data
=
data;
pnode
-
>
next
=
NULL;
if
(
head
=
=
NULL && displayPtr
=
=
NULL
)
{
head
=
pnode;
displayPtr
=
pnode;
}
else
{
head
-
>
next
=
pnode;
head
=
pnode;
}
}
void displayN
(
node
*
displayPtr
)
{
node
*
ptr
=
displayPtr;
while
(
ptr
!
=
NULL
)
{
cout
<
<
ptr
-
>
data;
if
(
ptr
-
>
next
!
=
NULL
)
cout
<
<
"
-
>
"
;
ptr
=
ptr
-
>
next;
}
cout
<
<
endl;
return;
}
int main
(
)
{
node
*
head
=
NULL;
node
*
displayPtr
=
NULL;
insertN
(
head
,
displayPtr,
1
)
;
insertN
(
head
,
displayPtr,
2
)
;
insertN
(
head
,
displayPtr,
3
)
;
cout
<
<
"Nodes in linked list."
<

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!