Course Solutions Uncategorized (Solved) : Complete C Function Find Length Linked List Include Using Namespace Std Class Node Public Q27477111 . . . .

(Solved) : Complete C Function Find Length Linked List Include Using Namespace Std Class Node Public Q27477111 . . . .

 

//Complete the C++ function to find the length of a linkedlist.

#include <iostream>

using namespace std;

class Node {
public:
Node *next;
int data;

Node(int d) {
data = d;
next = nullptr;
}
};

class LinkedList {
public:
Node *head;
Node *tail;
  
LinkedList() {
head = nullptr;
tail = nullptr;
}

void push(int data) {
Node *newNode = new Node(data);
if (!head) {
head = newNode;
tail = newNode;
} else {
tail->next = newNode;
tail = newNode;
}
}

int getCount() {
// Complete this Function
}

void deleteList() {
Node *curr = head;
Node *next = nullptr;
while (curr) {
next = curr->next;
delete curr;
curr = next;
}
head = nullptr;
}

};

int main() {
LinkedList l1;
l1.push(8);
l1.push(9);
l1.push(3);
l1.push(14);
l1.push(5);

LinkedList l2;
l2.push(8);
l2.push(18);

LinkedList l3;

LinkedList l4;
l4.push(42);

LinkedList l5;
l5.push(8);
l5.push(1);
l5.push(12);

cout << l1.getCount() << endl;
cout << “Expected: 5” << endl;

cout << l2.getCount() << endl;
cout << “Expected: 2” << endl;

cout <<

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

(Answered) : Problem 1 Draw Arrow Network Fowling Project Minimizing Use Dummies Activity Depends Upona Q34744143(Answered) : Problem 1 Draw Arrow Network Fowling Project Minimizing Use Dummies Activity Depends Upona Q34744143

<br/><img src="https://media.cheggcdn.com/media%2F6e2%2F6e2d835f-8a8c-45eb-8ec6-43d881a7da8b%2Fimage.png" alt="Problem #1 Draw Arrow Network for the fowling project (minimizing the use of dummies): Activity Depends uponActivity Depends" aria-describedby="j1t"/>Problem #1 Draw Arrow Network for the fowling project (minimizing