Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#include #include struct Node { int val; struct Node *next; }; void display_list(struct Node *head); void destroy_list(struct Node *head); struct Node *create_list(int startVal, int finishVal);

image text in transcribed

#include  #include  struct Node { int val; struct Node *next; }; void display_list(struct Node *head); void destroy_list(struct Node *head); struct Node *create_list(int startVal, int finishVal); struct Node *reverse(struct Node *head); struct Node *remove_Kth_from_end(struct Node *head, int k); void main() { struct Node *p = create_list(3,13); printf(" Created a list: "); display_list(p); p = reverse(p); printf("Reversed the list: "); display_list(p); destroy_list(p); p = create_list(3,13); printf(" Created a list: "); display_list(p); p =remove_Kth_from_end(p, 5); printf("Removed 5-th from end: "); display_list(p); destroy_list(p); } struct Node *reverse(struct Node *head) { return head; } struct Node *remove_Kth_from_end(struct Node *head, int k) { return head; } void display_list(struct Node *head) { printf("List: "); for (struct Node *p=head; p!=NULL; p=p->next) { printf("->%d ",p->val); } printf(" "); } void destroy_list(struct Node *head) { struct Node *p = head; while (p!=NULL) { struct Node *next = p->next; free(p); p = next; } return; } struct Node *create_list(int startVal, int finishVal) { struct Node *head = NULL; /* Head of the list */ struct Node *last = NULL; /* Last node in the list */ for (int i=startVal; ival = i; p->next = NULL; if (i == startVal) { head = p; } else { last->next = p; } last = p; } return head; } 
Problem 4 (not from the textbook). [2 pts] Attached with this homework is a file "list.c". The following functions do work: struct Node * reverse(struct node * head): Reverses the linked list and return its head Example: Input >L(0)>L(1)>L(2)>>L(n1)> NULL Output >L(n1)>L(n2)>.>L(1)>L(0)>NULL struct Node * remove_Kth_from_end(struct Node * head, int k); Removes the k-th node from the end of the linked list and return its head. Example: Input >L(0)>L(1)>L(2)>>L(n1)>NULL and k=2 Output >L(0)>L(1)>>L(n3)>L(n1)> NULL You may assume that k is valid, i.e., 1

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

Discuss what would be covered in a first interview with an athlete.

Answered: 1 week ago

Question

Identify three types of physicians and their roles in health care.

Answered: 1 week ago

Question

Compare the types of managed care organizations (MCOs).

Answered: 1 week ago