Answered step by step
Verified Expert Solution
Question
1 Approved Answer
2. Write down an implementation of the procedure DELETE_POSITONS_3^k of deleting all positions of the input list identified by math indices of the form 3*,
2. Write down an implementation of the procedure DELETE_POSITONS_3^k of deleting all positions of the input list identified by math indices of the form 3*, where k = 0,1,2,3, ... . Make sure your implementation properly treats lists of any length and the empty list as well. In your implementation you are only allowed to use the basic operations of the List ADT (of slide 7 of week 2 file), i.e. FIRST(L), END(L), RETRIEVE(p, L), LOCATE(x, L), NEXT(p, L), PREVIOUS(p, L), INSERT(x, P, L), DELETE(p, L), MAKENULL(L). 1. INSERT(x, p, L). Insert x at position p in list L, moving elements at p and following positions to the next higher position. That is, if L is a, a, ... Ang then L becomes a1, A2,. . . Up-1, X, Ap, ... An. If p is END(L), then L becomes 21, 22, ..., An, x. If list L has no position p, the result is undefined. 2. LOCATE(x,L). This function returns the position of x on list L. If x appears more than once, then the position of the first occurrence is returned. If x does not appear at all, then END(L) is returned. 3. RETRIEVE(p, L). This function returns the element at position p on list L. The result is undefined if p = END(L) or if L has no position p. Note that the elements must be of a type that can be returned by a function if RETRIEVE is used. In practice, however, we can always modify RETRIEVE to return a pointer to an object of type elementtype. 4. DELETE(p, L). Delete the element at position p of list L. If L is a1, 42,... An, then L becomes a1, 42, ... Ap-1, 2p+,... lm. The result is undefined if L has no position p or if p = END(L). 5. NEXT(p, L) and PREVIOUS(p, L) return the positions following and preceding position p on list L. If p is the last position on L, then NEXT(p, L) = END(L). NEXT is undefined if p is END(L). PREVIOUS is undefined if p is 1. Both functions are undefined if L has no position p. 6. MAKENULL(L). This function causes L to become an empty list and returns position END(L). 7. FIRST(L). This function returns the first position on list L. If L is empty, the position returned is END(L). 8. PRINTLIST(L). Print the elements of L in the order of occurrence. 2. Write down an implementation of the procedure DELETE_POSITONS_3^k of deleting all positions of the input list identified by math indices of the form 3*, where k = 0,1,2,3, ... . Make sure your implementation properly treats lists of any length and the empty list as well. In your implementation you are only allowed to use the basic operations of the List ADT (of slide 7 of week 2 file), i.e. FIRST(L), END(L), RETRIEVE(p, L), LOCATE(x, L), NEXT(p, L), PREVIOUS(p, L), INSERT(x, P, L), DELETE(p, L), MAKENULL(L). 1. INSERT(x, p, L). Insert x at position p in list L, moving elements at p and following positions to the next higher position. That is, if L is a, a, ... Ang then L becomes a1, A2,. . . Up-1, X, Ap, ... An. If p is END(L), then L becomes 21, 22, ..., An, x. If list L has no position p, the result is undefined. 2. LOCATE(x,L). This function returns the position of x on list L. If x appears more than once, then the position of the first occurrence is returned. If x does not appear at all, then END(L) is returned. 3. RETRIEVE(p, L). This function returns the element at position p on list L. The result is undefined if p = END(L) or if L has no position p. Note that the elements must be of a type that can be returned by a function if RETRIEVE is used. In practice, however, we can always modify RETRIEVE to return a pointer to an object of type elementtype. 4. DELETE(p, L). Delete the element at position p of list L. If L is a1, 42,... An, then L becomes a1, 42, ... Ap-1, 2p+,... lm. The result is undefined if L has no position p or if p = END(L). 5. NEXT(p, L) and PREVIOUS(p, L) return the positions following and preceding position p on list L. If p is the last position on L, then NEXT(p, L) = END(L). NEXT is undefined if p is END(L). PREVIOUS is undefined if p is 1. Both functions are undefined if L has no position p. 6. MAKENULL(L). This function causes L to become an empty list and returns position END(L). 7. FIRST(L). This function returns the first position on list L. If L is empty, the position returned is END(L). 8. PRINTLIST(L). Print the elements of L in the order of occurrence
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