Docsity

CSE 3210 Assignment 2: Recursive and Iterative Functions, List Manipulation - Prof. Kathle, Assignments of Computer Science

Toggle sidebar
bg1
CSE 3210 Assignment #2 – I don’t have many problems – so take your time
Due Tues. September 16
1. Write a recursive AND iterative function that takes two arguments - a list and a number - and if the
number is equal to any element of the list then the function returns the position of that element in the
list. If the number isn’t found, then the function returns nil. (The member function tells you if the
element is there, but it doesn’t tell you the position…so, you probably shouldn’t use that function.)
Example: (position ‘(a b c 3 d) 3) returns 4
Example : (position ‘ (a b c d 4) 5) returns nil
2. Write a function which removes an element from a list based on an input index and returns the list
WITHOUT that element. For example:
> (remover 2 '( a b c d))
(A C D)
> (remover 3 '( a b c d))
(A B D)
You CANNOT use nth.
3. Now…destroyer
Use your answer to number 2 to create a function that can eliminate the elements of a list based on
their location. Examples:
> (destroyer '( a b c d e f g h) '( 6 2))
(A C D E G H)
> (destroyer '(a b c) '(3 1))
(B)
> (destroyer '(a b c) '(3 2 1))
NIL
Turn the program in to the project called Second

Partial preview of the text

Download CSE 3210 Assignment 2: Recursive and Iterative Functions, List Manipulation - Prof. Kathle and more Assignments Computer Science in PDF only on Docsity!

CSE 3210 Assignment #2 – I don’t have many problems – so take your time

Due Tues. September 16

  1. Write a recursive AND iterative function that takes two arguments - a list and a number - and if the number is equal to any element of the list then the function returns the position of that element in the list. If the number isn’t found, then the function returns nil. (The member function tells you if the element is there, but it doesn’t tell you the position…so, you probably shouldn’t use that function.)

Example: (position ‘(a b c 3 d) 3) returns 4

Example : (position ‘ (a b c d 4) 5) returns nil

  1. Write a function which removes an element from a list based on an input index and returns the list WITHOUT that element. For example:

(remover 2 '( a b c d))

(A C D)

(remover 3 '( a b c d))

(A B D)

You CANNOT use nth.

3. Now…destroyer

Use your answer to number 2 to create a function that can eliminate the elements of a list based on their location. Examples:

(destroyer '( a b c d e f g h) '( 6 2)) (A C D E G H) (destroyer '(a b c) '(3 1)) (B) (destroyer '(a b c) '(3 2 1)) NIL

Turn the program in to the project called Second