Prateek K
2012-03-28 01:34:33 UTC
LISTEL,
(b) define a suitable data type for the list – let us call it LIST (Hint: Obviously it
would be of type pointer to LISTEL),
(c) write a C function for each of the following operations on the object LIST:
i. LIST construct (), which returns an empty list,
ii. short int is empty (LIST), which returns 1 if the passed list is empty and 0, otherwise,
iii. LISTEL head (LIST) which is to return the first element of the list; the input list does not get disturbed,
iv. LIST tail (LIST) which returns the tail of the list, i.e., the original list with its head (i.e., the first element) removed,
v. void printList (LIST) which prints the input list elements,
vi. LIST concat (LIST, LIST) which concatenates the second list at the end of
the first list,
vii. LIST insert (LIST, int, int) – inserts the second parameter at a position in the list designated by the third parameter and returns the new list ; note that when the third parameter is 1 the pointer to the first element itself gets changed but this is taken care of by having the datatype LIST itself as a pointer and having the function return this new pointer value to the calling function which can be assigned to the original pointer variable. However, here also you would gain in terms of uniformity if you use a dummy element at the beginning.
viii. LIST reverse (LIST), a recursive function which returns a list which is the reverse of the input list.
ix. LIST alternate (LIST, LIST) which takes two lists and returns a new list having elements chosen from the two lists alternatively; thus, in the new list, the first one will be the first element of the first list, the second one will be the first one of the second list, and so on. The original lists are left undisturbed.
x. Write a main function to demonstrate the working of the above functions.