Use main.cxx and dnode.h to modify dnode.cxx to come out with the output:   main.cxx: #include "dnode.h" int main() {     dnode* head_ptr = NULL;     int data[] = {5,9,11,2,3,8,7};     for (int i=0; i<(sizeof(data)/sizeof(int)); ++i)         dlist_head_insert(head_ptr, data[i]);     print_fore(head_ptr);     dnode* cursor = dlist_search(head_ptr, 2);     dlist_remove(cursor->back());     print_fore(head_ptr);     dlist_head_remove(head_ptr);     print_fore(head_ptr);     print_back(head_ptr);     dlist_head_remove(head_ptr);     print_fore(head_ptr);     dnode* cursor2 = dlist_search(head_ptr, 5);     dlist_remove(cursor2->back());     print_fore(head_ptr);     dnode* cursor3 = dlist_search(head_ptr, 9);     dlist_insert(cursor3,13);     print_fore(head_ptr);     dlist_remove(head_ptr);     print_fore(head_ptr);     print_back(head_ptr);     dlist_remove(head_ptr);     print_fore(head_ptr);     dlist_head_remove(head_ptr);     print_fore(head_ptr);     return 0; } dnode.h:   #ifndef DNODE_H #define DNODE_H #include class dnode { public:    typedef int value_type; dnode( const value_type& init_data = value_type( ), dnode* init_fore = NULL, dnode* init_back = NULL ) { data_field = init_data; link_fore = init_fore; link_back = init_back;} void set_data(const value_type& new_data) { data_field = new_data; } void set_fore(dnode* new_fore) { link_fore = new_fore; } void set_back(dnode* new_back) { link_back = new_back; }    value_type data( ) const { return data_field; } const dnode* fore( ) const { return link_fore; } dnode* fore( ) { return link_fore; } const dnode* back( ) const { return link_back; } dnode* back( ) { return link_back; } private: value_type data_field; dnode* link_fore; dnode* link_back; }; void dlist_head_insert(dnode*& head_ptr, const dnode::value_type& entry); void dlist_insert(dnode* previous_ptr, const dnode::value_type& entry); void dlist_head_remove(dnode*& head_ptr); void dlist_remove(dnode* previous_ptr); dnode* dlist_search(dnode* head_ptr, const dnode::value_type& target); void print_fore(const dnode* head_ptr); void print_back(const dnode* head_ptr); #endif dnode.cxx:   #include #include "dnode.h" void dlist_head_insert(dnode*& head_ptr, const dnode::value_type& entry) {      } void dlist_insert(dnode* previous_ptr, const dnode::value_type& entry) {      } void dlist_head_remove(dnode*& head_ptr) {      } void dlist_remove(dnode* previous_ptr) {      } dnode* dlist_search(dnode* head_ptr, const dnode::value_type& target) {      }   void print_fore(const dnode* head_ptr) {     const dnode *cursor;     for (cursor = head_ptr; cursor != NULL; cursor = cursor->fore())         std::cout << cursor->data() << " ";     std::cout << std::endl; } void print_back(const dnode* head_ptr) { const dnode *cursor = head_ptr; while (cursor->fore() != NULL) cursor = cursor->fore(); for (;cursor != NULL; cursor = cursor->back()) std::cout << cursor->data() << " "; std::cout << std::endl; } Output: 7 8 3 2 11 9 5 7 8 3 11 9 5 8 3 11 9 5 5 9 11 3 8 3 11 9 5 3 11 9 3 11 9 13 3 9 13 13 9 3 3 13 13

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

Use main.cxx and dnode.h to modify dnode.cxx to come out with the output:

 

main.cxx:

#include "dnode.h"

int main()
{
    dnode* head_ptr = NULL;
    int data[] = {5,9,11,2,3,8,7};

    for (int i=0; i<(sizeof(data)/sizeof(int)); ++i)
        dlist_head_insert(head_ptr, data[i]);
    print_fore(head_ptr);

    dnode* cursor = dlist_search(head_ptr, 2);
    dlist_remove(cursor->back());
    print_fore(head_ptr);

    dlist_head_remove(head_ptr);
    print_fore(head_ptr);
    print_back(head_ptr);

    dlist_head_remove(head_ptr);
    print_fore(head_ptr);

    dnode* cursor2 = dlist_search(head_ptr, 5);
    dlist_remove(cursor2->back());
    print_fore(head_ptr);

    dnode* cursor3 = dlist_search(head_ptr, 9);
    dlist_insert(cursor3,13);
    print_fore(head_ptr);

    dlist_remove(head_ptr);
    print_fore(head_ptr);
    print_back(head_ptr);

    dlist_remove(head_ptr);
    print_fore(head_ptr);

    dlist_head_remove(head_ptr);
    print_fore(head_ptr);

    return 0;
}

dnode.h:

 

#ifndef DNODE_H
#define DNODE_H

#include <cstdlib>

class dnode
{
public:
  
typedef int value_type;

dnode(
const value_type& init_data = value_type( ),
dnode* init_fore = NULL,
dnode* init_back = NULL
)
{ data_field = init_data; link_fore = init_fore; link_back = init_back;}


void set_data(const value_type& new_data) { data_field = new_data; }
void set_fore(dnode* new_fore) { link_fore = new_fore; }
void set_back(dnode* new_back) { link_back = new_back; }

  
value_type data( ) const { return data_field; }


const dnode* fore( ) const { return link_fore; }
dnode* fore( ) { return link_fore; }
const dnode* back( ) const { return link_back; }
dnode* back( ) { return link_back; }
private:
value_type data_field;
dnode* link_fore;
dnode* link_back;
};

void dlist_head_insert(dnode*& head_ptr, const dnode::value_type& entry);
void dlist_insert(dnode* previous_ptr, const dnode::value_type& entry);
void dlist_head_remove(dnode*& head_ptr);
void dlist_remove(dnode* previous_ptr);
dnode* dlist_search(dnode* head_ptr, const dnode::value_type& target);

void print_fore(const dnode* head_ptr);
void print_back(const dnode* head_ptr);

#endif

dnode.cxx:

 

#include <iostream>
#include "dnode.h"

void dlist_head_insert(dnode*& head_ptr, const dnode::value_type& entry)
{
    
}

void dlist_insert(dnode* previous_ptr, const dnode::value_type& entry)
{
    
}


void dlist_head_remove(dnode*& head_ptr)
{
    
}


void dlist_remove(dnode* previous_ptr)
{
    
}


dnode* dlist_search(dnode* head_ptr, const dnode::value_type& target)
{
    
}

 

void print_fore(const dnode* head_ptr)
{
    const dnode *cursor;
    for (cursor = head_ptr; cursor != NULL; cursor = cursor->fore())
        std::cout << cursor->data() << " ";
    std::cout << std::endl;
}


void print_back(const dnode* head_ptr)
{
const dnode *cursor = head_ptr;
while (cursor->fore() != NULL)
cursor = cursor->fore();
for (;cursor != NULL; cursor = cursor->back())
std::cout << cursor->data() << " ";
std::cout << std::endl;
}

Output:

7 8 3 2 11 9 5
7 8 3 11 9 5
8 3 11 9 5
5 9 11 3 8
3 11 9 5
3 11 9
3 11 9 13
3 9 13
13 9 3
3 13
13

 
 
Expert Solution
steps

Step by step

Solved in 4 steps with 3 images

Blurred answer
Knowledge Booster
Arrays
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