Question
Only the following functions are allowed to use in the application: struct listCDT { listElementT h; listADT t; }; typedef struct listCDT *listADT; typedef int
Only the following functions are allowed to use in the application:
struct listCDT { listElementT h; listADT t; };
typedef struct listCDT *listADT; typedef int listElementT;
listADT EmptyList() { return((listADT)NULL); }
listADT Cons(listElementT h1, listADT t1) { listADT list = (listADT) malloc(sizeof(*list)); list->h = h1; list->t = t1; return (list); }
listElementT Head(listADT list) { if (ListIsEmpty(list)) exit(EXIT_FAILURE); return (list->h); }
listADT Tail(listADT list) { if (ListIsEmpty(list)) exit(EXIT_FAILURE); return (list->t); }
int ListIsEmpty(listADT list) { return (list == NULL); }
1. Write the following function that makes use of the listADT of list of integers: listADT moveMinToHead(listADT); which moves the minimum element in the list to the head of the list if the argument list is nonempty, or returns an empty list otherwise. For examples, moveMinToHead([]) = [] moveMinToHead([3,4,8,2,4]) = [2,3,4,8,4] moveMinToHead([3,5]) = [3,5] moveMinToHead([7]) = [7] . a) Write this function as a recursive function. Hint: Call moveMinToHead with the tail as the argument. b) Write this function as a nonrecursive function. 1. Write the following function that makes use of the listADT of list of integers: listADT moveMinToHead(listADT); which moves the minimum element in the list to the head of the list if the argument list is nonempty, or returns an empty list otherwise. For examples, moveMinToHead([]) = [] moveMinToHead([3,4,8,2,4]) = [2,3,4,8,4] moveMinToHead([3,5]) = [3,5] moveMinToHead([7]) = [7] . a) Write this function as a recursive function. Hint: Call moveMinToHead with the tail as the argument. b) Write this function as a nonrecursive functionStep 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