Merge2AscListsRecur that combines the nodes in X-list and Y-list into Z-list such that, after calling the function, Z-list is a sorted list (in non-decreasing order) containing all the nodes initially contained in X-list and Y-list  –  X-list and Y-list should both be empty after the call.

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

Merge2AscListsRecur that combines the nodes in X-list and Y-list into Z-list such that, after calling the function, Z-list is a sorted list (in non-decreasing order) containing all the nodes initially contained in X-list and Y-list  –  X-list and Y-list should both be empty after the call.

The function should:
    Have only three parameters (each a pointer-to-Node) and no return value (be a void function).
    Not use any global variables or static local variables.
    Not use any looping constructs (forwhiledo-while, ...).
    Be directly (not indirectly) recursive.
    Not create any new nodes, destroy any existing nodes or copy/replace the data item of any node.
    Not make temporary copies of the data involved using any other storage structures (arrays, stacks, queues, etc.).
    Use (if ever needed) no more than a small number of pointers to hold certain link addresses.
      Not make temporary copies of the entire list's link addresses wholesale.
  Z-list should be sorted at all times as it "grows" from an empty list to one that contains all the nodes originally contained in X-list and Y-list.
    What this means is that you should not, for instance, attempt to first append all the nodes in X-list to Z-list, then append all the nodes in Y-list to Z-list, and finally use a sorting algorithm of some kind to sort the nodes in Z-list.

#ifndef LLCP_INT_H
#define LLCP_INT_H

#include <iostream>

struct Node
{
   int data;
   Node *link;
};

int    FindListLength(Node* headPtr);
bool   IsSortedUp(Node* headPtr);
void   InsertAsHead(Node*& headPtr, int value);
void   InsertAsTail(Node*& headPtr, int value);
void   InsertSortedUp(Node*& headPtr, int value);
bool   DelFirstTargetNode(Node*& headPtr, int target);
bool   DelNodeBefore1stMatch(Node*& headPtr, int target);
void   ShowAll(std::ostream& outs, Node* headPtr);
void   FindMinMax(Node* headPtr, int& minValue, int& maxValue);
double FindAverage(Node* headPtr);
void   ListClear(Node*& headPtr, int noMsg = 0);

// prototype of Merge2AscListsRecur


#endif

in
12345678981234567892812234252527829812345拓劲89842b4456F8498123456驭859 60
10
13
20
26
30
40
50
#include <iostream>
#include <cstdlib>
#include "11cpInt.h"
using namespace std;
// definition of Merge2AsclistsRecur
// (put here to facilitate grading)
int FindList Length (Node* headptr)
int length = 0;
while (headPtr != 0)
{
}
bool
{
}
{
}
++length;
headPtr = headPtr->link;
return length;
{
IsSortedUp (Node* headptr)
if (headPtr == 0 || headPtr->link == 0) // empty or 1-node
return true;
(headPtr->link != 0) // not at last node
void InsertAsHead (Node* & headPtr, int value)
{
while
if (headPtr->link->data < headPtr->data)
return false;
headPtr = headPtr->link;
}
return true;
void InsertAsTail (Node* & headPtr, int value)
newNodePtr->data
Node *newNodePtr = new Node;
= value;
newNodePtr->link = headPtr;
headPtr = newNodePtr;
Node *newNodePtr = new Node;
= value;
= 0;
newNodePtr->data
newNodePtr->link
if (headPtr == 0)
headPtr = newNodePtr;
else
{
Node *cursor = headPtr;
while (cursor->link != 0) // not at Last node
cursor = cursor->link;
cursor->link = newNodePtr;
void InsertSorted Up (Node* & headPtr, int value)
Transcribed Image Text:in 12345678981234567892812234252527829812345拓劲89842b4456F8498123456驭859 60 10 13 20 26 30 40 50 #include <iostream> #include <cstdlib> #include "11cpInt.h" using namespace std; // definition of Merge2AsclistsRecur // (put here to facilitate grading) int FindList Length (Node* headptr) int length = 0; while (headPtr != 0) { } bool { } { } ++length; headPtr = headPtr->link; return length; { IsSortedUp (Node* headptr) if (headPtr == 0 || headPtr->link == 0) // empty or 1-node return true; (headPtr->link != 0) // not at last node void InsertAsHead (Node* & headPtr, int value) { while if (headPtr->link->data < headPtr->data) return false; headPtr = headPtr->link; } return true; void InsertAsTail (Node* & headPtr, int value) newNodePtr->data Node *newNodePtr = new Node; = value; newNodePtr->link = headPtr; headPtr = newNodePtr; Node *newNodePtr = new Node; = value; = 0; newNodePtr->data newNodePtr->link if (headPtr == 0) headPtr = newNodePtr; else { Node *cursor = headPtr; while (cursor->link != 0) // not at Last node cursor = cursor->link; cursor->link = newNodePtr; void InsertSorted Up (Node* & headPtr, int value)
12345678的龙12345龙刀及刀812545跖初貂羽%吐2345678981 2 3456
70
80
90
99
100
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
Node *precursor = 0,
while (cursor != 0 && cursor->data < value)
}
precursor = cursor;
cursor = cursor->link;
Node *newNodePtr = new Node;
newNodePtr->data = value;
newNodePtr->link = cursor;
if (cursor == headptr)
headPtr = newNodePtr;
else
*cursor = headPtr;
precursor->link = newNodePtr;
/* using-only-cursor (no precursor) version
Node *newNodePtr = new Node;
newNodePtr->data = value;
= 0;
//newNodePtr->Link
//if (headPtr == 0)
{
headPtr = newNodePtr;
//else if (headPtr->data >= value)
//}
if (headPtr == 0 || headPtr->data >= value)
newNodePtr->link = headPtr;
headPtr = newNodePtr;
newNodePtr->link= headPtr;
headPtr = newNodePtr;
else
//else if (headPtr->Link == 0)
head->Link = newNodePtr;
Node *cursor = headPtr;
while (cursor->Link != 0 && cursor->Link->data < value)
cursor = cursor->Link;
//if (cursor->Link != 0)
newNodePtr->Link = cursor->Link;
newNodePtr->link = cursor->link;
cursor->link = newNodePtr;
}
else
{
Node *newNodePtr new Node;
newNodePtr->data = value;
if (headPtr == 0 || headPtr->data >= value)
{
newNodePtr->link= headPtr;
headPtr = newNodePtr;
Node *cursor = headPtr;
while (cursor->link != 0 && cursor->link->data < value)
cursor = cursor->link;
Transcribed Image Text:12345678的龙12345龙刀及刀812545跖初貂羽%吐2345678981 2 3456 70 80 90 99 100 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 Node *precursor = 0, while (cursor != 0 && cursor->data < value) } precursor = cursor; cursor = cursor->link; Node *newNodePtr = new Node; newNodePtr->data = value; newNodePtr->link = cursor; if (cursor == headptr) headPtr = newNodePtr; else *cursor = headPtr; precursor->link = newNodePtr; /* using-only-cursor (no precursor) version Node *newNodePtr = new Node; newNodePtr->data = value; = 0; //newNodePtr->Link //if (headPtr == 0) { headPtr = newNodePtr; //else if (headPtr->data >= value) //} if (headPtr == 0 || headPtr->data >= value) newNodePtr->link = headPtr; headPtr = newNodePtr; newNodePtr->link= headPtr; headPtr = newNodePtr; else //else if (headPtr->Link == 0) head->Link = newNodePtr; Node *cursor = headPtr; while (cursor->Link != 0 && cursor->Link->data < value) cursor = cursor->Link; //if (cursor->Link != 0) newNodePtr->Link = cursor->Link; newNodePtr->link = cursor->link; cursor->link = newNodePtr; } else { Node *newNodePtr new Node; newNodePtr->data = value; if (headPtr == 0 || headPtr->data >= value) { newNodePtr->link= headPtr; headPtr = newNodePtr; Node *cursor = headPtr; while (cursor->link != 0 && cursor->link->data < value) cursor = cursor->link;
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 3 steps with 3 images

Blurred answer
Knowledge Booster
Types of trees
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
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