Menu

[solved]-Ve Struggling Alot Working Data Structures Drracket M Hoping Get Help Solving Question 1 B Q39084544

I’ve been struggling alot with working with data structures inDrRacket. I’m hoping I can get some help solving question #1 a) andb).

1. Lists? We dont need no stinking lists!. Recall that we defined a (listof Int) as follows: A (listof Int) is either . O,

1. Lists? We don’t need no stinking lists!. Recall that we defined a (listof Int) as follows: A (listof Int) is either . ‘O, or • (cons v L) where v is an Int and L is a (listof Int). We then used the built-in functions first and rest to extract parts of the list, and the built-in function cons to make a list one longer. Here we will create a structure that is able to store arbitrarily long data, just like a list. For clarity, we will consider only storing Int values, but the same structure would work for any value, just like a list. For this question, use the following data definition: (define-struct ls (first rest)) ii a Ls is either ;; O, or ; ; (make-ls first rest) where first is an Int and rest is a Ls. Keep in mind that since the structure is named ls, and its fields are named first and rest, you will access these fields using ls-first and ls-rest. Exercise (a) Length. Write a function (1s-length L) that consumes a Ls and returns the number of values in it. For example, W (check-expect (1s-length (make-ls 5 (make-1s 7 (make-1s 11 ‘O)))) 3) Exercise (b) Max. Write a function (Is-max L) that consumes a non-empty Ls and returns the largest value. For example, (check-expect (1s-max (make-1s 5 (make-1s 11 (make-1s 7 ‘O)))) 11) 2. Summarizing Data. Exercise Write a function (remove-item L item) that returns L with all copies of item removed. (remove-item (list 42 “a” “bee” “sea” “bee” 17) “bee”) => (list 42 “a” “sea” 17) Show transcribed image text 1. Lists? We don’t need no stinking lists!. Recall that we defined a (listof Int) as follows: A (listof Int) is either . ‘O, or • (cons v L) where v is an Int and L is a (listof Int). We then used the built-in functions first and rest to extract parts of the list, and the built-in function cons to make a list one longer. Here we will create a structure that is able to store arbitrarily long data, just like a list. For clarity, we will consider only storing Int values, but the same structure would work for any value, just like a list. For this question, use the following data definition: (define-struct ls (first rest)) ii a Ls is either ;; O, or ; ; (make-ls first rest) where first is an Int and rest is a Ls. Keep in mind that since the structure is named ls, and its fields are named first and rest, you will access these fields using ls-first and ls-rest. Exercise (a) Length. Write a function (1s-length L) that consumes a Ls and returns the number of values in it. For example, W (check-expect (1s-length (make-ls 5 (make-1s 7 (make-1s 11 ‘O)))) 3) Exercise (b) Max. Write a function (Is-max L) that consumes a non-empty Ls and returns the largest value. For example, (check-expect (1s-max (make-1s 5 (make-1s 11 (make-1s 7 ‘O)))) 11) 2. Summarizing Data. Exercise Write a function (remove-item L item) that returns L with all copies of item removed. (remove-item (list 42 “a” “bee” “sea” “bee” 17) “bee”) => (list 42 “a” “sea” 17)

Expert Answer


Answer to I’ve been struggling alot with working with data structures in DrRacket. I’m hoping I can get some help solving question… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *