Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function called copyList(), which makes a deep copy or complete copy of one singly linked list. The copy must contain the data in

  1. Write a function called copyList(), which makes a deep copy or complete copy of one singly linked list. The copy must contain the data in the same order as the original list. The function should accept two parameters: a pointer to the source list and a pointer to the copy list. You need to decide if the pointers are single indirection (*) or double indirection (**). The function should not return a value. Note: a deep copy implies that new dynamic memory is allocated for each node in the copy list. You should NOT just do the following:

copyList = sourceList;

You may not assume that a makeNode() function exists. Assume the following node definition:

typdef struct node

{

int data;

struct node *pNext;

} Node;

Be sure to write out the function header!

  1. Write a recursive C function called findMax() that recursively searches two linked lists for the maximum integer. The function returns a pointer to the Node that contains the maximum integer. If the maximum integer occurs more than once, then return a pointer to any of the possible nodes. The lists must also contain an equal number of nodes. Note: the lists may be empty.

Assume that struct node is defined as follows:

typedef struct node

{

int data;

struct node *pNext;

} Node;

Use the following function header:

Preconditions: Length(pList1) == Length(pList2); pMax == NULL

Node * findMax(Node *pList1, Node *pList2, Node *pMax)

{

  1. Write a C function insertAtEnd() for a doubly linked list that has the following header:

int insertAtEnd (struct node **pStart, char *pNewData);

The variable pStart indirectly references the front of the list and the variable pNewData is a pointer to contiguous memory (string) that should be copied into the new node. The function must insert a new node, at the end or back of the linked list, with the data value pNewData. The function must return 1 if the node was successfully added to the end; 0 otherwise. Assume that struct node is defined as follows:

struct node

{

char *pData;

struct node *pNext; // points to next node in sequence

struct node *pPrev; // points to previous node in sequence

};

You must implement the dynamic memory allocation for a node inside of insertAtEnd(). Hint: make sure that you also allocate space for the string.

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

Graph Database Modeling With Neo4j

Authors: Ajit Singh

2nd Edition

B0BDWT2XLR, 979-8351798783

More Books

Students also viewed these Databases questions

Question

Find y'. y= |x + X (x) (x) X 1 02x+ 2x 1 O 2x + 1/3 Ex 2x +

Answered: 1 week ago

Question

1. Discuss the potential legal issues that relate to training.

Answered: 1 week ago

Question

3. Design a program for preparing for cross-cultural assignments.

Answered: 1 week ago

Question

2. Develop a program for effectively managing diversity.

Answered: 1 week ago