Question: Implement an insert member function for a CircularlyLinkedList class that stores ints. Your insert function should accept the int to insert and the position in

Implement an insert member function for a CircularlyLinkedList class that stores ints. Your insert function should accept the int to insert and the position in the list where the new element should be added. E.g., list.insert(100, 1) should add a node with value 100 in index 1 of the list (between the first and second elements of the old list). You may assume that the position argument will be in the range 0 to size (inclusive), and you may assume that the list contains at least 1 element.

The CircularlyLinkedList class has a Node* pointer to the tail of the list and int size, and each Node has int data and Node* next. You may assume that the Node class has a constructor that accepts a data value and a constructor that accepts a data value and a Node* pointer. You may also assume that your insert function has friend access to the data members of Node.

You will need to update the size data member of CircularlyLinkedList, and you will need to update tail when inserting at position size.

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!