正在加载图片...
6.001, Spring Semester, 2005--Quiz Il Now we want to add a new element to a cycle. This means we want to insert a new cons cell, wit h the supplied argument as its car, before the lo cat ion in the cy cle current ly pointed to by the supplied argument. We are going to treat this as a mut ator(that is, it changes an exist ing dat a struct ure), so we do not want to rely on the value ret urned by the procedure. Hence by convention, let's have the procedure ret urn the sy mbol done. Here is an example behavior define test-cycle (list->cycle '(a b c g))) Value: test-cycle (head test-cy cle) head (rotate-left (rotate-left test -cycle))) Value: c (insert-cy cle! (rotate-left (rotate-left test-cycle))'x)) d test-cy cle head (rotate-left (rotate-left test-cycle))) Value: x head (rotate-left (rotate-left (rotate-left test-cy cle)))) Value: c non-empty cycle. You should use rotate-left and /or rotat e-right where approprlate nt is a Question 3: Write the procedure insert-cycle!. You may assume that the argume￾       6 , , ,    ,    .! )% % , ,  %  , ￾ & ,) ) %  % % ￾& 0 )   ) . .   0. ) % ! :     )% %   ?) %&  )%  <%  %B& % ,   ,  .  ) -  0. ) ! & 0. -& 3% )- )   ) %.0 !  %  < 0)-2 ￾   ￾  ￾      ￾     ￾ ￾  ￾     ￾  ￾  ￾       ￾     ￾ ￾  ￾      ￾ ￾  ￾  ￾     ￾   : )   ￾ ￾ !  . %% ) )  %  7. .!  %) %     C     ,) !
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有