// other functions omitted... void insert (const Item áx, int i) { // Copy this function in the answer and write code below this line. };

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter17: Linked Lists
Section: Chapter Questions
Problem 5PE
icon
Related questions
Question
Implement the insert function in SLList class to insert an item x at a particular position in the list indexed by i. For example, let L= [1,2,3]. A call toL.insert (4,1) will make L=[1,4,2,3].
You should not change the item of existing nodes.
Below is a skeleton of the Node and SLList class:
template <typename ItemType> class Node
public:
ItemType item;
Node *next;
Node (ItemIype i, Node *n = nullptr) {
item - i;
next = n;
} ;
template <typename ItemType> class SLList {
private:
/** Pointer pointing to the sentinel node. */
Node<ItemType> *sentinel;
/** Stores the current size of the list. */
int count;
public:
// Other functions omitted...
void insert (const Item &x, int i) {
// Copy this function in the answer and write code below this line.
}
};
Transcribed Image Text:Implement the insert function in SLList class to insert an item x at a particular position in the list indexed by i. For example, let L= [1,2,3]. A call toL.insert (4,1) will make L=[1,4,2,3]. You should not change the item of existing nodes. Below is a skeleton of the Node and SLList class: template <typename ItemType> class Node public: ItemType item; Node *next; Node (ItemIype i, Node *n = nullptr) { item - i; next = n; } ; template <typename ItemType> class SLList { private: /** Pointer pointing to the sentinel node. */ Node<ItemType> *sentinel; /** Stores the current size of the list. */ int count; public: // Other functions omitted... void insert (const Item &x, int i) { // Copy this function in the answer and write code below this line. } };
Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning