Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions