Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

IntegerLinkedList.h #pragma once // ADD ANSWER TO THIS FILE #pragma once class SNode { public: int elem; SNode *next; }; class IntegerLinkedList { private: SNode

IntegerLinkedList.h

#pragma once

// ADD ANSWER TO THIS FILE

#pragma once

class SNode {

public:

int elem;

SNode *next;

};

class IntegerLinkedList {

private:

SNode *head;

public:

IntegerLinkedList() {

head = nullptr;

}

void addFront(int x) {

SNode *tmp = head;

head = new SNode;

head->next = tmp;

head->elem = x;

}

int getInteger(int i); // COMPLETE THIS FOR PROBLEM 2

};

//cpp.

// EDIT THIS FILE ONLY FOR YOUR OWN TESTING

// WRITE YOUR CODE IN IntegerLinkedList.h

//

#include #include

#include "IntegerLinkedList.h"

using namespace std;

int main() {

IntegerLinkedList mylist;

cout << "Enter number of integers : ";

int n, value;

cin >> n;

cout << "Enter " << n << " integers" << endl;

for (int i = 0; i < n; i++) {

cin >> value;

mylist.addFront(value);

}

cout << "Integer at node 0: " << mylist.getInteger(0) << endl;

cout << "Integer at node 3: " << mylist.getInteger(3) << endl;

}

sample run:

enter number of integers:6

enter 6 integers: 35 20 25 30 15 10

integers at node 0: 10

integers at node 3 : 25

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Administration The Essential Reference

Authors: Brian Laskey, David Kreines

1st Edition

1565925165, 978-1565925168

More Books

Students also viewed these Databases questions