1 Singly Linked List A linked list is a data structure where elements are connected to form a chain where each node points to the next one in the order. Ezercise: Given the code of the Node struct, implement a singly linked list with the following functionalities: • addFront: add an integer key to the front of the list. • remove: deletes the smallest number larger than or equal the passed integer and returns the deleted value. If no number is found, returns -1. All cases must be handled. You can define any helper method as needed. #include #include #define INF INT_MAX // indicates infinity value using namespace std; struct Node int key; Node next; Node (int key) this->key - key; this->next - NULL; }; class SinglyLinkedList public: SinglyLinkedList () head - NULL; void addFront (Node+ node) 1 int remove(int val) private: Node head; }; int main() SinglyLinkedList sLL - nev SinglyLinkedList (); Node* nodel = nev Node (5); Node node2 - nev Node (13) ; Node node3 - nev Node (7); SLL->addFront (node1); //5 SLL->addFront (node2); //13 5 SLL->addFront (node3); //7 13 5 cout << sLL->remove (6) << endl; //7 cout « sLL->remove (7) <« endl; //13 return 0;

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%
1
Singly Linked List
A linked list is a data structure where elements are connected to form a chain where each node points to
the next one in the order.
Exercise:
Given the code of the Node struct, implement a singly linked list with the following functionalities:
• addFront: add an integer key to the front of the list.
• remove: deletes the smallest number larger than or equal the passed integer and returns the deleted
value. If no number is found, returns -1.
All cases must be handled. You can define any helper method as needed.
#include <iostream>
#include <climits>
#define INF INT_MAX // indicates infinity value
using namespace std;
struct Node
int key;
Node next;
Node(int key)
{
this->key - key;
this->next- NULL;
};
class SinglyLinkedList
public:
SinglyLinkedList ()
head - NULL;
void addFront (Node* node)
1
int remove(int val)
{
private:
Node head;
};
int main()
{
SinglyLinkedList sLL - neu SinglyLinkedList ();
Node* nodel = new Node (5);
Node node2 - neu Node (13);
Node node3 - nev Node(7);
BLL->addFront (node1); //5
SLL->addFront (node2); //135
SLL->addFront (node3); //7 13 5
cout « sLL->remove (6) <« endl; //7
cout « sLL->remove (7) <« endl; //13
return 0;
Transcribed Image Text:1 Singly Linked List A linked list is a data structure where elements are connected to form a chain where each node points to the next one in the order. Exercise: Given the code of the Node struct, implement a singly linked list with the following functionalities: • addFront: add an integer key to the front of the list. • remove: deletes the smallest number larger than or equal the passed integer and returns the deleted value. If no number is found, returns -1. All cases must be handled. You can define any helper method as needed. #include <iostream> #include <climits> #define INF INT_MAX // indicates infinity value using namespace std; struct Node int key; Node next; Node(int key) { this->key - key; this->next- NULL; }; class SinglyLinkedList public: SinglyLinkedList () head - NULL; void addFront (Node* node) 1 int remove(int val) { private: Node head; }; int main() { SinglyLinkedList sLL - neu SinglyLinkedList (); Node* nodel = new Node (5); Node node2 - neu Node (13); Node node3 - nev Node(7); BLL->addFront (node1); //5 SLL->addFront (node2); //135 SLL->addFront (node3); //7 13 5 cout « sLL->remove (6) <« endl; //7 cout « sLL->remove (7) <« endl; //13 return 0;
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY