1 -> 6 -> 2 -> 4 -> 5 -> 3 -> 8
Addition of Two Numbers
Adding two numbers in programming is essentially the same as adding two numbers in general arithmetic. A significant difference is that in programming, you need to pay attention to the data type of the variable that will hold the sum of two numbers.
C++
C++ is a general-purpose hybrid language, which supports both OOPs and procedural language designed and developed by Bjarne Stroustrup. It began in 1979 as “C with Classes” at Bell Labs and first appeared in the year 1985 as C++. It is the superset of C programming language, because it uses most of the C code syntax. Due to its hybrid functionality, it used to develop embedded systems, operating systems, web browser, GUI and video games.
In this coding question for linked lists, you may assume that the list use sentinels or not use sentinels. The choice is yours. but you must pick. If you wish to use sentinel nodes, you must clearly put in a comment before your code that you will be using sentinels. If the statement is not present I will assume you are not using sentinels.
Suppose you were given the following declaration for a node and linked list. Every function listed below is a function you can call without implementing. Any function not listed below must be coded by you.
class DList{
struct Node{
int data_;
Node* next_;
Node* prev_;
Node(int data = 0, Node* nx=nullptr, Node* pr=nullptr){...}
};
Node* front_;
Node* back_;
public:
class const_iterator{
Node* curr_;
friend class DList;
const_iterator(Node* p){...}
public:
const_iterator(){...}
const_iterator operator++(){...}
const_iterator operator++(int){...}
const_iterator operator--(){...}
const_iterator operator--(int){...}
const T& operator*() const {...}
bool operator==(const_iterator){...}
bool operator!=(const_iterator){...}
};
class iterator:public const_iterator{
...
iterator(Node* p){...}
friend class DList;
public:
iterator(){...}
iterator operator++(){...}
iterator operator++(int){...}
const_iterator operator--(){...}
const_iterator operator--(int){...}
T& operator* {...}
};
DList(){...}
const_iterator cbegin()const{...}
const_iterator cend()const{...}
iterator begin(){...}
iterator end(){...}
};
Write the following member function:
int DList::eraseAllEvenNumbers();
This function will erase all even numbers from the list and return the number of values erased.
For example suppose you had the following list:
1 -> 6 -> 2 -> 4 -> 5 -> 3 -> 8
This function would erase the nodes with 6,2,4 and 8 At the end, the following list would remain:
1 -> 5 -> 3
function returns 4 because 4 numbers were removed.
Step by step
Solved in 2 steps