收藏 分享(赏)

cs106x midterm examination.pdf

上传人:weiwoduzun 文档编号:1752353 上传时间:2018-08-22 格式:PDF 页数:10 大小:104.26KB
下载 相关 举报
cs106x midterm examination.pdf_第1页
第1页 / 共10页
cs106x midterm examination.pdf_第2页
第2页 / 共10页
cs106x midterm examination.pdf_第3页
第3页 / 共10页
cs106x midterm examination.pdf_第4页
第4页 / 共10页
cs106x midterm examination.pdf_第5页
第5页 / 共10页
点击查看更多>>
资源描述

1、 p CS106X Handout 26 Autumn 209 November 4th, 209 CS106X Midterm Examination This is an open-note exam. You can refer to any course handouts, handwriten lecture notes, and printouts of any code relevant to a CS106X asignment. You may not use any laptops, cel phones, or handheld devices of any sort.

2、Anyone taking the exam remotely can cal in to ask questions: 415-205-242. Once remote students are done, they should fax al pages to 650-723-6092. God luck! Section Leader: _ Last Name: _ First Name: _ I acept the leter and spirit of the honor code. Ive neither given nor received aid on this exam. I

3、 pledge to write more neatly than I ever have in my entire life. (signed) _ Score Grader 1. Publishing Stories (8) _ _ 2. Numeric Palindromes (12) _ _ 3. Character Swaps (10) _ _ 4. Linked List Fun (15) _ _ Total (45) _ _ SCPD students who want their exams sent back through regular mail, check here:

4、 _2 Problem 1: Publishing Stories (8 points) Social networking sites like Facebok, LinkedIn, Orkut, and MySpace typically record and publish stories about actions taken by you and your friends. Stories such as: John Dixon accepted your friend request. Jeff Barbose is no longer in a relationship. Sco

5、t James wrote a note called “The Two Percent Solution“. Arlene Heitner comented on Melodie Bowshers video. Antonio Melara gave The French Laundry a 5-star review. are created from story templates like name accepted your friend request. name is no longer in a relationship. name wrote a note called “t

6、itle“. name comented on targets video. actor gave restaurant a rating-star review. The specific story is generated from the skeletal one by replacing the tokenssubstrings like “name“, “title“, and “rating“with event-specific values, like “John Dixon“, “The Two Percent Solution“, and “5“. The token-v

7、alue pairs can be packaged in a Map, and given a story template and a data map, its posible to generate an actual story. Write the SubstituteTokens function, which accepts a story template (like “actor gave restaurant a rating-star review.“) and a Map (which might map “actor“ to “Antonio Melara“, “r

8、estaurant“ to “The French Laundry“, and “rating“ to “5“), and builds a string just like the story template, except that the tokens have been replaced by the text they map to. Place your implementation on the next page, and feel free to rip this page out so you can easily refer to it. Asume the folow

9、ing is true: and exist to delimit token names, but wont appear anywhere else. In other words, if you encounter the character, you can assume it marks the begining of a token that ends with a . We guarantee that all tokens are in the Map. You dont need to do any error checking. Note that the and the

10、arent included in the map. “name“, for instance, is replaced with whatever “name“ identifies in the map. 3 Problem 1 (continued) string SubstituteTokens(string storyTemplate, Map node *next; ; a. (5 points) Write the Intermingle function, which takes a linked list of integers and inserts a new node

11、in between every one of the originals, where the value in each new node is the diference between the numbers on either side of it. Here are some examples: list list after call Intermingle(list) 1 4 2 1 -3 4 2 2 3 3 6 1 1 1 2 6 5 1 0 1 0 1 -1 2 void Intermingle(node *list) 9 Problem 4 (continued) b.

12、(10 points) Write the Cluster function, which updates a linked list of integers so that all instances of the same number are grouped together while retaining the order in which each number first appears. For instance, the list: Before: 4 1 4 5 5 2 2 1 5 would become After: 4 4 1 1 5 5 5 2 2 Note tha

13、t the original list introduces 4, then 1, then 5, and then 2. That means the transformed list brings all 4s to the front, folowed by all 1s, folowed by all 5s, folowed by all 2s. Some more examples: list list after call Cluster(list) 8 7 14 8 7 8 8 7 7 14 7 7 4 1 4 5 4 3 4 5 4 4 4 4 4 4 1 5 5 3 Use the next page for your implementation (and feel free to rip this page out so you can easily refer to it.) You can take as many passes over the list as you need to to get the desired transformation. 10 Problem 4 (continued) void Cluster(node *list)

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 企业管理 > 经营企划

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报