tailieunhanh - How to Design Programs phần 10
Bởi vì các điều kiện trên các lĩnh vực của một cấu trúc inex rất nghiêm ngặt, chúng tôi sử dụng chức năng tạo-inex để tạo ra các cấu trúc này. Hình 94 có chứa các định nghĩa chức năng cho createinex, mà là một nhà xây dựng tổng quát, có nghĩa là, một nhà xây dựng kiểm tra (xem phần 7,5). | 3. In the second case the natural recursion adds a new card to the end of a-hand. Indeed because the given a-hand isn t the last one in the chain the natural recursion does everything that needs to be done. Here is the complete definition of add-at-end add-at-end rank suit hand - void effect to add a card with v as rank and s as suit at the end of a-hand define add-at-end rank suit a-hand cond empty hand-next a-hand set-hand-next a-hand make-hand rank suit empty else add-at-end rank suit hand-next a-hand It closely resembles the list-processing functions we designed in part II. This should come as no surprise because add-at-end processes values from a class that closely resembles the data definition of lists and the design recipes are formulated in a general manner. Exercise . Evaluate the following program by hand Test the function with this example. Make up two other examples. added and a prediction examples. Formulat Exercise . Develop define hand0 create-hand 13 SPADES 1 DIAMONDS hand0 2 CLUBS hand0 begin add-at-end add-at-end hand0 function last-card. It consumes a hand and produces a list with call th the last card s rank and suit. How can we use this function to test the add-at-end function ch example consists of an initial hand cards to be esult should be. Then test the function with the additional -valued expressions. Exercise . Suppose a family tree consists of structures that record the name social security number and parents of a person. Describing such a tree requires a structure definition define-struct child name social father mother and a data definition A family-tree-node short ftn is either 1. false or 2. make-child name socsec f m where name is a symbol socsec is a number and f and m are ftns. For now we assume that everyone has a social security number and that social security numbers are unique. -506- TEAM FLY PRESENTS Following our convention from part III false represents a lack of knowledge about someone s father or mother.
đang nạp các trang xem trước