In c++, 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.
A doubly linked list is a linked list in which navigation is possible in both forward and backward ways. Here "prev" link points to the "next" link of previous element and "next" link points to the "previous" link of next element and each link carries a data field to contain the data.
Please find the solution below. Here we will insert the data in a doubly linked list first then we will print the data inside the linked list.
#include <iostream>
using namespace std;
// doubly linked list node
struct Node {
int data; // to hold an integer value
struct Node *next; // Pointer to next node
struct Node* prev; // Pointer to previous node
};
struct Node* head = NULL;
void insert_operation(int new_data) { // insert function will
insert the data at the beginning of the doubly linked list
struct Node* newnode = (struct Node*) malloc(sizeof(struct Node));
// allocating a block of uninitialized memory
newnode->data = new_data;
newnode->prev = NULL;
newnode->next = head;
if(head != NULL) {
head->prev = newnode ;
}
head = newnode;
}
void print() { // print() function will print the elements of the
doubly linked list
struct Node* ptr;
ptr = head;
while(ptr != NULL) {
cout<< ptr->data <<" ";
ptr = ptr->next;
}
}
int main() {
int len,j;
cout<< "How many integer you want to insert in the linked
list ? ";
cin >> len ;
for (int i=0; i<len;i++){
cout<< "Enter the value : ";
cin >> j ;
insert_operation(j);
}
cout<<"The doubly linked list is:\n ";
print();
return 0;
}
OUTPUT:

In c++, write a function that prints every other element in a linked list. Assume that...
In C++
Assume entries in a linked list are of type struct
listrec:
struct listrec
{
struct listrec *prev;
float
value;
struct listrec *next;
};
listrec *head, *tail;
Write a main() routine in which the user is asked the
number of nodes to create in the list (number greater than or equal
to zero) then create the following type of linked list (use a loop
to initialize list) based on the number of nodes requested:
Write a...
Write a C function that iterates through a singly linked list and converts it to a doubly linked list. Your solution must NOT create a second list. You must come up with the appropriate parameters and return type. Note: the nodes in the singly linked list have a field for a previous pointer, but that field has not initially been set in any of the nodes. You must do this as part of your solution!
Write a Java class myLinkedList to simulate a singly linked list using arrays as the underlying structure. Include the following methods: 1. insert an element within the linked list.(this should also work for the front and the rear of the list) 2. Remove an element from the linked list 3. Display (print) the elements of the linked list in order. 4. A method to check if the list is "empty". Test your solution using a linked list that initially has...
implement a doubly-linked list in C. Each node in the linked list should contain a string, a pointer to the previous node (or NULL), and a pointer to the next node (or NULL). The nodes should be sorted by their strings. struct node_t { char* str; struct node_t* prev; struct node_t* next; } To maintain the doubly-linked list, you should keep a pointer to the head node of the list (or NULL if the list is empty), and a pointer...
Submit the pseudo code. Write a member function PrintReverse that prints the elements on a list in reverse order. For instance, for the list X Y Z, list. PrintReverse() would output element in the list. You may assume that the list is not empty.
Draw a sketch of a singly linked list containing the following int values: 3, 1, 4, 1, 5. The 3 should be at the front of the list. Remember to sketch the head pointer, each node, and each node's next pointer. 2. Write the code for the following new member function for our SinglyLinkedList class. You should write out the definition of the function, but do not need to write out all of the rest of the class. Your code...
This is a c programming problem.
Would you please help me to write this problem???
I really appreciate it if you add comments for explanation step
by step.
Thank you.
Reverse a Doubly linked list using recursion: Given a doubly linked list. Reverse it using recursion. Original Doubly linked list: next pointer - DDHIHI Null prev painter Reversed Doubly linked list: next pointer Start Pointer Null prev pointer Include: a) A struct for a node of the doubly linked list....
Assume entries in a linked list are of type struct listrec: struct listrec { char value; struct listrec *next; }; Write a main() routine in which you create the following linked list: | a | --|----> | c | --|-----> | w | --|----> NULL Write a function called printlist that takes a pointer to the start of a linked list and prints out all the nodes in the list in sequence. The inferface of this function...
c++ only Program 2: Linked List Class For this problem, let us take the linked list we wrote in a functional manner in a previous assignment and convert it into a Linked List class. For extra practice with pointers we’ll expand its functionality and make it a doubly linked list with the ability to traverse in both directions. Since the list is doubly linked, each node will have the following structure: struct Node { int number; Node * nextNode;...
Linked list is a type of data structure. Each item of the list holds a data and a pointer to the next item. Head is a pointer that points to the first element. Tail is the last element of the list, which points to "NULL". Linked list can be implemented using structures, consisting of some data types and a pointer. Write a program that creates the linked list given in the following figure and prints out the data in order....