Introduction需要提交的文件为:DLList.c testList.c截图1和截图2是对task1的测试截图3是task2的输出结果Task2结果说明:1、 用DLListBefore向空链表中插入一个元素2、 删除这个元素3、 用DLListAfter向空链表中插入一个元素4、 用DLListBefore向链表中插入一个元素5、 用DLListAfter向链表中插入一个元素6、 依次删除所有元素Requirement2017/8/11 COMP2521 17s2 - Week 03 Lab Exercise1/6COMP2521 17s2Week 03 Lab ExerciseData Structures and AlgorithmsMyEd and DLLsObjectivesto illustrate file manipulationto implement a doublylinked list ADTto design comprehensive testcasesto build a simple linebased text editorAdminMarks 5=outstanding, 4=very good, 3=adequate, 2=substandard, 1=hopelessDemo in the Week 03 Lab or in the Week 04 LabSubmit give cs2521 lab03 DLList.c testList.c or via WebCMSDeadline must be submitted by 11:59pm on Sunday 13 AugustAimsThis lab aims to reexamine an idea that we have looked at a few times in lectures (without being explicit aboutit): command interpreters. More importantly, it aims to give you practice manipulating a useful data type:doublylinked lists. Finally, it aims to demonstrate how files are manipulated in Linux. These ideas are tiedtogether in a simple text editor, a program in the style. of the classic Unix text editor ed , an editor which roamedthe earth contemporaneously with the dinosaurs.BackgroundA text editor deals with a file of text, reads it, allows the user to modify it, and then writes it back. This impliesthat the editor has an internal representation that it deals with in between the reading and the writing. For thisexample, we consider that the internal representation is a sequence of lines, represented by a doublylinked listof strings. Each node in the list represents one line in the file being edited.Since a common operation is to “move around” the file, looking for lines to change, a doublylinked list with anotion of a current node provides a convenient way to do this. The editor itself is implemented as a loop which:prints a prompt, reads a command, carries out the command (possibly changing the state of the list), and thenrepeats. Many of the programs that we build for exploring data structures during this course will have a similarstructure. ( The fact that it prints a prompt is an improvement on the real ed editor, which doesn’t. Not prompting the user may beminimalist, but isn’t great interface design).Doublylinked ListsDoublylinked lists are a variation on “standard” linked lists where each node has a pointer to the previous nodeas well as a pointer to the next node. The following diagram shows the differences:2017/8/11 COMP2521 17s2 - Week 03 Lab Exercise2/6As shown in the diagram, our version of doublylinked lists also has a notion of a “current” node, and currentcan move backwards and forwards along the list. Our doublylinked list does insertions either immediatelybefore or immediately after the current node. Deletion always causes the current node to be removed from thelist.In this lab, we’ll use a doublylinked list ADT called DLList whose interface is given in the file/home/cs2521/web/17s2/labs/week03/code/DLList.hThe representation of DLList is a doublylinked list of DLListNode s, accessed via a record containing thefollowing four fields:nitems : a count of the number of nodes/items in the listfirst : a pointer to the first node in the listlast : a pointer to the last node in the listcurr : a pointer to the “current” node in the listSeveral important conditions must hold at all times during the lifetime of a DLList . Technically, theseconditions are called invariants, and are checked for in the function validDLList() .Whenever the list is nonempty, it must have a defined current node. It is not possible for the currentnode pointer to be NULL if there is at least one node in the list.The counter nitems must always contain a value which is the same as the number of nodes in the list.The bookkeeping operations (e.g. newDLList() , getDLList() , etc.) are relatively straightforward, sowe’ll describe only the operations relevant for this lab in detail.char DLListCurrent(DLList L)Return a pointer to the string value for the current node. It is an error to call this function if the listcontains no nodes.int DLListMove(DLList L, int n)Move the current pointer either backwards or forwards n positions from the current position. Moveforwards in n is positive, and move backwards if n is negative. If current reaches either end of the listbefore it has moved n positions, it stops at the end node. If the movement stops with current at either thefirst or last node, return a value of 1; otherwise, return a value of 0.int DLListMoveTo(DLList L, int n)Set the current pointer to point to the n th node in the list, where nodes are indexed starting from 1. If n issmaller than 1, the current node will be set to the first node. If n is larger than the number of nodes inthe list, the current node will be set to the last node. The return value has the same behaviour as thereturn value of DLListMove() .void DLListBefore(List, char )2017/8/11 COMP2521 17s2 - Week 03 Lab Exercise3/6Insert a new node in the list immediately before the current node. The new node becomes the currentnode. If the node is inserted before the first node, it also becomes the new first node.void DLListAfter(List, char *)Insert a new node in the list immediately after the current node. The new node becomes the currentnode. If the node is inserted after the last node, it also becomes the new last node.void DLListDelete(List)Remove the current node from the list (and free its memory, including the memory used to hold thestring). The current node becomes the node immediately following the node that was removed. If theremoved node is the last node (i.e. the node at the end of the list), then the current node is set to the newlast node. If the node removed was the only node in the list, then current becomes NULL. IfDLListDelete() is called with an empty list, it should simply return without making any changes tothe list.Note that the supplied DLList ADT implements a doublylinked list of strings. The strings are created outsidethe list nodes, as in the diagram below:The storage used by the strings needs to be managed separately to the storage used by the list nodes,although still as part of the implementation of the DLList ADT.myed : a Text EditorText editors are programs that allow you to manipulate text files interactively; they provide a user interfacewhere you can load a file, make changes to it, and then save an updated version of the file. Text editors likemyed are seriously retro and hark back to the 60’s, when screenbased editors like vi and emacs didn’t exist,and graphical editors like gedit weren’t even a gleam in some inventor’s eye (except maybe Doug Engelbart).The myed program provides an extremely simple commandline interface where you enter onelettercommands to manipulate the loaded file. Despite its primitive interface, myed can actually make changes totext files. Here’s an example session with the editor (using the normal notational conventions: what the systemprints is in this font , what you type is in this font , comments are in small grey font ).$ .C代写 Week 03 Lab Exercise代做留学生php语言/myed text // start the editor, loading a file called “text”> % // show all of the lines in the filethis is // the current line is the first linea small filecontaining a few linesof boring text> . // show the current linethis is> i // insert a line before the first linenew first line // you type the new line here> % // show all of the lines again, so you can see the changesnew first line // note that the new line is now the current linethis isa small filecontaining a few linesof boring text2017/8/11 COMP2521 17s2 - Week 03 Lab Exercise4/6> n // move to the next linethis is> n // move to the next linea small file> n // move to the next linecontaining a few lines> -2 // move back two linesthis is> w // save a copy of the modified file> q // quit the editor$ ls // list the files in the current directory… text text.new … // should see the original file and the new version$ cat text.new // look at the contents of the new text filenew first linethis isa small filecontaining a few linesof boring text$The best way to get a feeling for how the editor works is to play with it. There’s a working version in the classdirectory, which you can execute on the CSE lab machines via the command:$ /home/cs2521/web/17s2/labs/week03/myed FileNameChoose any old text file you like as the filename. Once you have an editor prompt, the command ? will tell youwhat other commands are available.If you play with the supplied myed , I can guarantee that you will run the % command a lot. Editing is betterwhen you get immediate feedback on the changes you’ve made, which led to the development of screenbasededitors like vi and emacs soon after the novelty of editing in the ed style. wore off (and once graphicaldisplays were available). If you’re keen to experience the original ed , it’s still available under Linux.Setting UpSet up a directory for this lab under your cs2521/labs directory, change into that directory, and run thefollowing command:$ unzip /home/cs2521/web/17s2/labs/week03/lab03.zipIf you’re working at home, download lab03.zip , unzip it there, and then work on your local machine.If you’ve done the above correctly, you should now find the following files in the directory:Makefile a set of dependencies used to control compilationDLList.h interface definition for the List ADTDLList.c (partial) implementation for the List ADTtestList.c main program for testing the List ADTmyed.c main program for a simple linebased text editortext a simple text file that you can use to test myedOnce you’ve got these files, the first thing to do is to run the command$ makeThis will produce messages about compiling with gcc and will put two executable files in your directory (alongwith some .o files).testL2017/8/11 COMP2521 17s2 - Week 03 Lab Exercise5/6This is the executable for the testList.c program. As supplied, it runs a number of simple tests onthe DLList datatype. You can use it by running ./testL , typing in a few lines of text and then usingcontrlD to end the input; the program should display all of the lines you typed and not produce anyassert errors. You will need to add more extensive tests as part of this Lab.myedThis is the executable for the myed.c program, which implements a very simple linebased text editor. Ittakes as argument a file name, reads this file into a doublylinked list of lines, and then supports variousactions on the lines. See the myed.c file for details on what commands are available, or type the ?command inside the editor to get help.Since myed is a text editor, it needs to be invoked by giving it a file to edit. The lab.zip archivecontains a small text file (called text ) that you can use with the editor. Invoke the editor using acommand like:./myed textTask 1The myed program is complete, but doesn’t work because some of the functions in DLList.c are notcomplete. You should complete these functions so that the behaviour of your myed program is the same as thebehaviour of the sample solution:$ /home/cs2521/web/17s2/labs/week03/myed textYou can execute the sample solution on the CSE workstations (only), by typing the full path name exactly asabove. It would be a good idea to play with the sample solution at least briefly to get an idea of how it issupposed to work.Note that since the two myed programs read from stdin and write to stdout , one automatic way of testingthem would be to devise a set of editing scripts (files containing sequences of myed commands), and thenapply each script. with both your myed and the sample myed and using diff to ensure that they both producethe same output, e.g.$ ./myed text out1$ /home/cs2521/web/17s2/labs/week03/myed text out2$ diff out1 out2In order to establish the correctness of your myed , you should develop a number of editing scripts, each onebeing more devious than the previous in attempting to crash your editor (and the sample one, if you can … ifyou do work out how to crash the sample editor, let me know, and I’ll fix it).Task 2Implementing the DLList functions to make myed work serves two purposes: (a) getting a complete editor,(b) myed providing a simple test harness for the DLList ADT. However, the way that myed exercises theADT is by no means complete, and more testing is needed.The testList.c program provides a skeleton in which to build a more serious testing framework. Atpresent, it is minimal; it simply uses the getDLList() function to read some strings from standard input intoa List , displays the List and then does a sanity check on the representation. You should expandtestList.c to provide a more complete set of tests to exercise the DLList functions.Note that writing a detailed test suite for all functions in the ADT is quite time consuming. You should at leastwrite comprehensive test cases for the three functions that you implemented. This means that you should havea test for each of the possible states in which each function might be invoked (e.g. empty list, list with onenode, etc.). At the least, each test should:show the state of the list before the operation (including curr and nitems )indicate what operation is about to be performedinvoke the operationdisplay the state of the list after the operation2017/8/11 COMP2521 17s2 - Week 03 Lab Exercise6/6run the validDLList() check on the listYou can simply use visual inspection of the output to check whether the operations have worked correctly, and,of course, check with validDLList() after each operation. It is not necessary to write automatic checks ofthe precise state, since this would require writing multiple functions almost as complex as validDLList() .If you wish to modify putDLList() to give a better display of the DLList state (e.g. use short lines anddisplay all of them on a single output line), that would be useful (but not essential).SubmissionYou need to submit two files: DLList.c and testList.c . Submit these either via the give command in aterminal window or from WebCMS, and then show your tutor, who’ll give you feedback on your coding style,your test quality, and award a mark.Have fun, jas转自:http://ass.3daixie.com/2019030627560482.html
讲解:C Week 03 Lab Exercisephp
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- By clicking to agree to this Schedule 2, which is hereby ...
- 我们在开发过程中有时会遇到Fragment内容重叠的情况,其具体原因可以参考这篇文章:从源码角度分析,为什么会发生...