Question

Write a function that prints every other element in a linked list. Assume that it is...

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.

Homework Answers

Answer #1

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;

    }

}

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
In C++ please Implement a class for doubly linked list. Your doubly linked list should have...
In C++ please Implement a class for doubly linked list. Your doubly linked list should have following members: - A head pointer - A tail pointer - Function: insert at head -Function: insert at tail - Function: delete a node - Function: search a node - Function: traverse - Function: reverse traverse Test your implementation by calling member functions inside main.
Please answer in C A doubly linked list is a list in which each entry contains...
Please answer in C A doubly linked list is a list in which each entry contains a pointer to the preceding entry in the list as well as a pointer to the next entry in the list. Define the appropriate structure for the doubly linked list. Write a user space program that implements a doubly linked list and prints out the elements of the list. Develop insert_entry() and remove_entry() functions for this list. The link list should store information on...
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings....
C PROGRAMMING Doubly Linked List For this program you’ll implement a doubly linked list of strings. You must base your code on the doubly linked list implementation given in my Week 8 slides. Change the code so that instead of an ‘int’ each node stores a string (choose a suitable size). Each node should also have a next node pointer, and previous node pointer. Then write functions to implement the following linked list operations: • A printList function that prints...
C LINKED LIST #include <stdlib.h> #include <stdio.h> //Struct for a polynomial term (double linked list object)...
C LINKED LIST #include <stdlib.h> #include <stdio.h> //Struct for a polynomial term (double linked list object) typedef struct Polynomial t_Polynomial; typedef struct Term { // coefficient of the polynomial term associated with the object int coef;    // power of the polynomial term associated with the object int power;    // pointer to the next object (to facilitate a doubly linked list) struct Term *next;    // pointer to the previous object (to facilitate a doubly linked list) struct Term...
Implement a function that reverses a singly linked list in one pass of the list. The...
Implement a function that reverses a singly linked list in one pass of the list. The function accepts a pointer to the beginning of the list and returns a pointer to the beginning of the reversed list. The function must not create any new nodes. Be sure to test your function! You may start with code that you have written for other labs. This is a common interview question!
Write a function to accept a header of a sorted linked and a name which can...
Write a function to accept a header of a sorted linked and a name which can be used as a key. If the key is found then add the record to the linked list using pointer(s). Do not write complete program. Write just one function. I just need a function that can demonstrate the prompt above.
Write C language code for a function that takes a doubly linked list as a parameter...
Write C language code for a function that takes a doubly linked list as a parameter and deletes all the nodes in even positions from the first to the last after displaying the content of each node to the console.
Write Pseudocode to remove the node at position 1 in a doubly-linked list. Assume position follows...
Write Pseudocode to remove the node at position 1 in a doubly-linked list. Assume position follows classic indexing from 0 to item_count - 1, and there is a node at position 2.
write a function to delete the largest item from a sorted (asc) Circular Linked List (a...
write a function to delete the largest item from a sorted (asc) Circular Linked List (a CLLNode is list where the last element is pointing to head).
C++ questions QUESTION 1 What kind of linked list begins with a pointer to the first...
C++ questions QUESTION 1 What kind of linked list begins with a pointer to the first node, and each node contains a pointer to the next node, and the pointer in the last node points back to the first node? A. Circular, singly-linked list. B. Circular, doubly-linked list. C. Singly-linked list. D. Doubly-linked list. E. None of the above.    QUESTION 2 _________ is not an advantage of linked lists when compared to arrays. A. Dynamic memory allocation. B. Efficient...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT