Introduction
:
#include
#include
#include
#include “listIteratorInt.h”
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;
/
Your local functions here, if any….
/
IteratorInt IteratorIntNew(){
Node tmp;
tmp=malloc(sizeof(Node));
tmp->next=NULL;
tmp->front=NULL;
tmp->next_data=NULL;
tmp->front_data=NULL;
IteratorInt list;
list=malloc(sizeof(IteratorIntRep));
list->p=tmp;
list->flag=0;
return list; // you need to change this…
}
void reset(IteratorInt it){
if(it!=NULL)
{
it->flag=0;
while(it->p->front!=NULL)
{
it->p=(Node )(it->p->front);
}
}
}
listIteratorInt.clistIteratorG.c
Requirement
COMP1927: Assignment 1
Generic 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.
Objectives
to give you experience in implementing generic ADTs in C
to give you (more) experience with doubly-linked lists
to give you further practice with C and data structures
to look at a (yet another) simple command interpreter
Admin
Marks 10 marks (9 marks towards total course mark)
Group? This assignment is completed individually
Due 23:55pm on Monday Week-7 (10 April 2017).
Late
Penalty 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.
Aim
In 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.
Iterator
An 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-1
IteratorInt 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 th†⁴†⁵†⁷ ⁴⡎⥥ⱸ⁴⁴ⱴ⁴‾†⁶⠠⥭Ɐ⡴䥳⁷†ⱥ†⁷†‰ ⥳⁐
⁴ ⁵††㩬⁴††Ⱐ⁴†‼
ㅉ⁴ⰼひ†㱳⽥㸠൰੯⡥䤠䝬⁵⥩㱮⽥㸠൧੩⁴ㄠ⁵⁴†Ⱶび⁴㱭⽤㸠൷੩⡶䥩䝧⥡㱣⽮㹤ഠ੦⁎ㅯ⁴⁴†⁸⁹ⱴの㱴⽳㸠൮੯⁴†⡥䤮䜊⤠㰠⽶㹩൯ੵ⁴‾⁰†⁶⁵⸠††⁔†Ɒ⁴⁷⁴⠠††††⥳†䱥䱬†㱴⼠㹲ੴ†⁎⡴䤠䝰⥩㱯†⽶㹡൬ੵ‾⁴⁴
‾⁄⁴†⁴††⁹⁴⁵⁎Ⱐ⁴†⁍⁔⁙⸠⡡†⁰⁵⁸⁵⤬†⁴⁸䱰䱬†
ⸯ㰾⁔⽨㹩൳ਠ⡮䥬䝤⥮㱣⁰⽥㹲ഠ䑡⁵⁴⁴⁹⁴㱥⁴⽨㹥ഠ੬㩮䅸⁴⁰⁶⁸䥴䴠䵯䕲䐠䥦䅩䕤䱐‾ ⁴‼†⁴㱵⽤㸠ൢㄠ⁰⁶Ɱぎ⡐ⱨ†⥮㰠
⼮㸼ൢੲ ⁴†⁴⁴†⁍⁔⁙⁹⁵†䥯†⁴⁶††⁸⁐‼ †⁵⸩㰮⼠㸯ാ⡡䥬䝥†Ɽ⁹†⤠㱮⁴⽨㹥൲ਠ†††⁴†⁴†⠮⥨㱳⽬㹬ഠ㩡䅥†††⁸䥴䴠䵯䕲䐠䥰䅲䕶䱩⁵⁸†⁶⁎†㱵⼠㹴൨ㄠ⁴⁴ⱬ⁵づ†⁴⠠Ⱐ⁶⤠㱤⽣㹥൳ਠ⁎⁌†⁵⁴⁴⁴†ⸯ‾⁴⁴††⁶†㱵⽮㸠൩ੴ⁴†⡴䥨䜠⁶Ⱶ⥯㱶†⽴㹨ਠ⁰† ††⁌⁴⸠㱦⁴⼠㹨ൡੳ†⁵†䱡䱴†⁴‼†††⁴⁴†⸮㰼†⼯㸾ਊ′⡳䥴䝯Ⱳ†
⨴†⥲㱫‼⽢㹲ഠਯ⁰⁴††⁴††⁹†㱴⽡㹣ਠ⁴†䱵䰠⁴†⁴⁵†⁵†㱬⽮㹧ഠ੭⡦䥩䝉⁴⥡㱴⁇⼮㹣ബਠ⁴㱢⼠㹩൮ਠ㰻⽩㹮ദੲ䑤⽣㈠㌯㨾㔍㔊⁷䵡㜠⁐⡡ㅲぴ䄲㈱ばㄲ㜮⥺㱰⽲㸠യਾ⁉ㄠⱐ‼ †⁴ⵯㅲ⹇㱒†⽉㹴ੲ†㉹Ɒ†
㉴⸠㱥†⽶㹯൩㰻⼠㸯ാ⁹䕳‱‾⁰†⁆
⁇⁃䥯⁰Ⱐ⁅⁃⁹⁆††⁴⁷†††䥤⁉†⁶† ⱥ†䈠⁴ 䰀 䌀 䠀 ⸀ 䄀 ⸀ Ⰰ Ⰰ ⸀ 䘀 Ⰰ 䌀 䤀⸀㰀 ⼀㸀ഀ☀㬀 ☀㬀㰀⼀㸀