讲解:C++ COMP1927 Assignment 1C/C++ Assignment

Introduction示范代码:typedef struct {int next_data;int front_data;struct Node next;struct Node front;} Node;typedef struct IteratorIntRep {Node p;int flag; //0 none - next/findnext + Previous/findPrevious 2 setdelete 1 delete} IteratorIntRep;已通过测试提交时只需要提交listIteratorInt.c和listIteratorG.cRequirementCOMP1927: Assignment 1Generic Iterator ADT(Draft v4, last modified at 5pm Friday 07 April)This is an initial draft, and it may change! A notice on the class web page will be posted after each revision, so please check class notice board frequently.Change log:(v4) if a call to next, prev, findNext or findPrevious is not successful, cursor is not moved from the current position. For v4, see text with lightgreen background..(v3) the word IMMIDIATELY added in the descriptions of “delete” and “set” operations. For v3, see text with orange background.(v2) Revised descriptions/requirements of “delete” and “set” operations to reduce possible ambiguity. For v2, see text with yellow background.(v2) Submission instructions added.Objectivesto give you experience in implementing generic ADTs in Cto give you (more) experience with doubly-linked liststo give you further practice with C and data structuresto look at a (yet another) simple command interpreterAdminMarks 10 marks (9 marks towards total course mark)Group? This assignment is completed individuallyDue 23:55pm on Monday Week-7 (10 April 2017).LatePenalty 2 marks per day off the ceiling (10 marks)(e.g. if you are 2 days late, your maximum possible marks is 6/10)The last day to submit late is 15 April 2017, after this date, you will receive zero mark for this assignment.AimIn this assignment, your task is to implement two listIterator ADTs, one for integer values in Part-1 (6 marks) and another for generic data types in Part-2 (4 marks). You will have to write wrapper code to test your implementations, and make sure to test a variety of conditions.Please note that, you need to submit only the C code implementing the required listIterator ADTs. Submit file listIteratorInt.c for Part-1 and file listIteratorG.c for Part-2.IteratorAn iterator offers an easy way to traverse through a collection, add new elements, delete and modify existing elements. Iterators are widely supported by langauges like C++ and Java. However, C does not offer iterators. In this assignment your task is to implement two list iterators that allow the programmer to traverse the list in either direction, modify the list during iteration, and obtain the iterator’s current position in the list.You will implement list iterators similar to the one available in Java. The following interface specifications are drawn from Java (7) ListIterator API and adapted for C implementations.A List Iterator has no current element; its cursor position always lies between the element that would be returned by a call to previous and the element that would be returned by a call to next. An iterator for a list of length n has n+1 possible cursor positions, as illustrated by the carets (^) below:Element(0) Element(1) Element(2) … Element(n-1)cursor positions: ^ ^ ^ ^ ^Note that the delete and set methods are not defined in terms of the cursor position; they are defined to operate on the last element returned by a call to next or previous.Part-1: List iterator for integer values(6 marks)First, implement a list iterator that can store integer values and offer the following interface to the programmer. You must use doubly linked list to implement your list iterator.Download files for Part-1: ass1p1.zip.Log from sample tests: sample_tests_log1.txt.You need to implement the following methods in the file listIteratorInt.c. Note that you need to submit ONLY one file, listIteratorInt.c, for this part. Please do not modify the header file listIteratorInt.h. You can write your test code in testListIteratorInt.c. However, you will not submit your test code. We will test your implementation using our test sets, so make sure you do NOT modify function headers (signatures) in the header file listIteratorInt.h.Interface for Part-1IteratorInt IteratorIntNew()Creates a new list iterator that can store integer values.int add(IteratorInt it, int v)Inserts the specified value v into the list iterator it. The element is inserted immediately before the element that would be returned by next(), if any, and after the element that would be returned by previous(), if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. Returns 1 if successful, 0 otherwise.int hasNext(IteratorInt it)Returns 1 if the given list iterator has more elements when traversing the list in the forward direction, returns 0 otherwise.int hasPrevious(IteratorInt it)Returns 1 if the given list iterator has more elements when traversing the list in the reverse direction, returns 0 otherwise.int next(IteratorInt it)Returns the pointer to the next value in the given list iterator and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.) The method returns NULL if it has no next value.int previous(IteratorInt it)Returns the pointer to the previous value in the given list iterator and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.) The method returns NULL if it has no previous value.int delete(IteratorInt it)Deletes from the list iterator the last value that was returned by next or previous or findNext or findPrevious.Precondition: A call to delete must be IMMEDIATELY preceded by a successful call to one of next or previous or findNext or findPrevious.Returns 1 if successful, 0 otherwise (for example, invalid delete call).This call can only be made onceC++代写 COMP1927 Assignment 1帮写C/C++ Assignment per call to next or previous or findNext or findPrevious. It can be made only if add or reset has not been called after the last call to next or previous or findNext or findPrevious.int set(IteratorInt it, int v)Replaces the last element (v) returned by next or previous or findNext or findPrevious with the specified element (v).Precondition: A call to set must be IMMEDIATELY preceded by a successful call to one of next or previous or findNext or findPrevious.Returns 1 if successful, 0 otherwise (for example, invalid set call).This call can be made only if neither of delete or add or reset have been called after the last call to next or previous or findNext or findPrevious. This call can only be made once per call to next or previous or findNext or findPrevious.int findNext(IteratorInt it, int v)Returns the pointer to the next value in it that matches the given value v and advances the cursor position.The method returns NULL and the cursor is not moved from the current position, if it has no next value that match v.int findPrevious(IteratorInt it, int v)Returns the pointer to the previous value in it that matches the given value v and moves the cursor position backwards.The method returns NULL and the cursor is not moved from the current position, if it has no previous value that match v.void reset(IteratorInt it)Resets it to the start of the list.Part-2: Generic List iterator(4 marks)In this part, you need to implement a generic list iterator that can store values of any type, and offer the following interface to the programmer. You must use doubly linked list to implement your list iterator. You need to implement the following methods in file listIteratorG.c, and submit this file as describe above in the “Admin” section.Download files for Part-2: ass1p2.zip.Interface for Part-2typedef struct IteratorGRep IteratorG;typedef int (ElmCompareFp)(void const e1, void const e2);typedef void (ElmCopyFp)(void const e1);typedef void (ElmFreeFp)(void e1);IteratorG IteratorGNew(ElmCompareFp cmp, ElmCopyFp copy, ElmFreeFp free)Creates a new generic list iterator with given functions to handle values.int add(IteratorG it, void vp)Inserts the specified value poined by vp into the list iterator it. The element is inserted immediately before the element that would be returned by next(), if any, and after the element that would be returned by previous(), if any. (If the list contains no elements, the new element becomes the sole element on the list.) The new element is inserted before the implicit cursor: a subsequent call to next would be unaffected, and a subsequent call to previous would return the new element. Returns 1 if successful, 0 otherwise.int hasNext(IteratorG it)Returns 1 if the given list iterator has more elements when traversing the list in the forward direction, returns 0 otherwise.int hasPrevious(IteratorG it)Returns 1 if the given list iterator has more elements when traversing the list in the reverse direction, returns 0 otherwise.void next(IteratorG it)Returns the pointer to the next value in the given list iterator and advances the cursor position. This method may be called repeatedly to iterate through the list, or intermixed with calls to previous to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.) The method returns NULL if it has no next value.void previous(IteratorG it)Returns the pointer to the previous value in the given list iterator and moves the cursor position backwards. This method may be called repeatedly to iterate through the list backwards, or intermixed with calls to next to go back and forth. (Note that alternating calls to next and previous will return the same element repeatedly.) The method returns NULL if it has no previous value.int delete(IteratorG it)Deletes from the list iterator the last value that was returned by next or previous or findNext or findPrevious.Precondition: A call to delete must be IMMEDIATELY preceded by a successful call to one of next or previous or findNext or findPrevious.Returns 1 if successful, 0 otherwise (for example, invalid delete call).This call can only be made once per call to next or previous or findNext or findPrevious. It can be made only if add or reset has not been called after the last call to next or previous or findNext or findPrevious.int set(IteratorG it, void vp)Replaces the last element returned by next or previous or findNext or findPrevious with the specified element (vp).Precondition: A call to set must be IMMEDIATELY preceded by a successful call to one of next or previous or findNext or findPrevious.Returns 1 if successful, 0 otherwise (for example, invalid set call).This call can be made only if neither of delete or add or reset have been called after the last call to next or previous or findNext or findPrevious. This call can only be made once per call to next or previous or findNext or findPrevious.void findNext(IteratorG it, void vp)Returns pointer to the next value in it that matches the value pointed to by vp. and advances the cursor position.The method returns NULL if there is no such next value and the cursor is not moved from the current position.void findPrevious(IteratorG it, void * vp)Returns pointer to the previous value in it that matches the value pointed to by vp and moves the cursor position backwards.The method returns NULL if there is no such previous value and the cursor is not moved from the current position.void reset(IteratorG it)Resets it to the startof the list.SubmissionDue date/time is 23:55pm on Monday Week-7 (10 April 2017).To Submit Part-1, goto the Submission page for Part-1.To Submit Part-2, goto the Submission page for Part-2.PlagiarismThis is an individual assignment. Each student will have to develop their own solution without help from other people. In particular, it is not permitted to exchange code or pseudocode. You are not allowed to use code developed by persons other than yourself. If you have questions about the assignment, ask your tutor Before submitting any work you should read and understand the following very useful guide by the Learning Centre How Not To Plagiarise. All work submitted for assessment must be entirely your own work. We regard unacknowledged copying of material, in whole or part, as an extremely serious offence. For further information, see the Course Information.– end –转自:http://ass.3daixie.com/2019031022472263.html

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,509评论 6 504
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,806评论 3 394
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 163,875评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,441评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,488评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,365评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,190评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,062评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,500评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,706评论 3 335
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,834评论 1 347
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,559评论 5 345
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,167评论 3 328
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,779评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,912评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,958评论 2 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,779评论 2 354

推荐阅读更多精彩内容

  • pyspark.sql模块 模块上下文 Spark SQL和DataFrames的重要类: pyspark.sql...
    mpro阅读 9,451评论 0 13
  • 函数调用 Built-in Functions abs(x) Return the absolute value ...
    叫我七夜阅读 1,170评论 0 0
  • ``` /* * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject ...
    非专业码农阅读 336评论 0 0
  • 今天是什么日子 起床:哈哈 没起来躺了一上午 就寝:估计得晚十二点左右 天气:气温23,天气晴朗和昨天一样 心情:...
    破土树阅读 209评论 0 1
  • 本文参加#未完待续,就要表白#活动,本人承诺,文章内容为原创,且未在其他平台发表过。 当我将故事写完,再也没有接下...
    疯左阅读 301评论 0 1