Question: USE C + + Write a function that returns the data of the k th element of a doubly linked list. If the number is

USE C++
Write a function that returns the data of the k th element of a doubly linked list. If the number is negative, start looking from the end. If it is positive, then start looking from the head. NOTE: The function takes only an integer and a pointer to the head. There is no pointer to tail.
The list will not be empty. The argument K will not be outside the list. K will not be 0. There is no tail. This is a doubly linked list.
For example, given the following data:
\table[[Node 1(head),Node 2,Node 3,Node 4,Node 5],[10,20,30,40,50]]
Example
The 4 th item is 40.
The -4 th item is 20
struct doubly{
int item;
doubly "next;
doubly "prev;
}:
int getltem(int k, doubly "head){
??? Code to deal with k when it is a positive number if ()
//Code to deal with k if it is negative number else
 USE C++ Write a function that returns the data of the

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!