Question
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
-
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!
-
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)
{
-
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started