Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include struct Node { int mData; struct Node * mNext; } ; / / This function updates a singly linked list into a circular

#include
#include
struct Node{
int mData;
struct Node* mNext;
};
// This function updates a singly linked list into a circular singly linked list
struct Node* makeListCircular(struct Node* pHead){
}
// This function prints "numNodes" number of nodes in a circular linked list
void printCircularLinkedList(struct Node* pHead, int numNodes){
printf("Circular linked list %d items
",numNodes);
// Start of your implementation
// End of your implementation
printf("
`");
}
void printLinkedList(struct Node* pHead){
printf("Linked list:
");
while (pHead != NULL)
{
printf("%d ",pHead->mData);
pHead = pHead->mNext;
}
printf("
");
}
int main(void){
struct Node* n1=(struct Node*) malloc(sizeof(struct Node));
struct Node* n2=(struct Node*) malloc(sizeof(struct Node));
struct Node* n3=(struct Node*) malloc(sizeof(struct Node));
struct Node* n4=(struct Node*) malloc(sizeof(struct Node));
struct Node* n5=(struct Node*) malloc(sizeof(struct Node));
struct Node* n6=(struct Node*) malloc(sizeof(struct Node));
if ((n1== NULL)||
(n2== NULL)||
(n3== NULL)||
(n4== NULL)||
(n5== NULL)||
(n6== NULL))
{
printf("There is an error in memory allocation, exiting!
");
return -1;
}
n1->mData =1;
n1->mNext = n2;
n2->mData =2;
n2->mNext = n3;
n3->mData =3;
n3->mNext = n4;
n4->mData =4;
n4->mNext = n5;
n5->mData =5;
n5->mNext = n6;
n6->mData =6;
n6->mNext = NULL;
struct Node* head = n1;
// Print #1
printLinkedList(head);
head = makeListCircular(head);
printCircularLinkedList(head,20);
// Print # 2
n1->mNext = NULL;
printLinkedList(head);
head = makeListCircular(head);
printCircularLinkedList(head,20);
// Print # 3
head = NULL;
printLinkedList(head);
head = makeListCircular(head);
printCircularLinkedList(head,20);
return 0;
}

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

More Books

Students also viewed these Databases questions