Write a function that prints every other element in a linked list. Assume that it is a member function of a doubly linked list. This means you will need to use pointer operations.
As you said you only need function, so here it is :
void
printAlternateNode(
struct
Node*
head)
{
int
count = 0;
while
(head != NULL)
{
//
when count is even print the nodes
if
(count % 2 == 0)
cout
<< head->data <<
"
"
;
//
count the nodes
count++;
//
move on the next node.
head
= head->next;
}
}
Get Answers For Free
Most questions answered within 1 hours.