1 -> 6 -> 2 -> 4 -> 5 -> 3 -> 8

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

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.

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Introduction to Coding
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education