class list_t
list_t
object
iterators
list_t
object in the
list.h
interface to a doubly-linked list,
with link_t *head
and
link_t *tail
nodes,
// - instance methods
// constructors (overloaded)
- (id) init;
// accessor/mutator
// operators
- (litr_t *) push_back: (id) _data;
- (litr_t *) insert: (litr_t *) _litr: (id) _data;
- (void) pop_front;
- (litr_t *) erase: (litr_t *) _litr;
// members
- (id) front;
- (id) back;
- (litr_t *) begin;
- (litr_t *) end;
- (bool) empty;
link_t
object that contains
id data;
, link_t *prev;
, and
link_t *next;
pointers along with corresponding
accessor/mutator member functions
link_t *current;
pointer from the
list_t
structure—this pointer now is moved
into its own object definition, litr_t
, and as
such, the litr_t
object must now be provided
with constructors, accessor/mutator functions as well as
operators next
and prev
which
advance or move back the current pointer and return itself.
litr_t
object should also have a bool
member function called equiv
which tests another
litr_t
object for equivalence (whether their
current pointers point to the same thing).
data_t
object definition as in an earlier lab.
main()
routine works unaltered:
int main(int argc, const char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
NSString *str;
int num;
char nam[NAME_LEN];
list_t *list = [(list_t *)[list_t alloc] init];
litr_t *litr = nil;
data_t *data = nil;
NSLog(@"main start");
while(scanf("%s %d",nam,&num) == 2) {
//fprintf(stderr,"%s %d\n",nam,num);
//str = [[NSString alloc] initWithCString: nam]; // deprecated, do not use
str = [[NSString alloc] initWithUTF8String: nam];
// cast sender to proper class type eliminates warning about amgiguous init
//[list insert: [list end]: [(data_t *)[data_t alloc] init: str: num]];
[list push_back: [(data_t *)[data_t alloc] init: str: num]];
}
NSLog(@"printing list");
litr = [list begin];
while(![litr equiv: [list end]]) {
[[litr data] print: stderr];
[litr next];
}
NSLog(@"printing list");
for(litr = [list begin]; ![litr equiv: [list end]]; [litr next])
[[litr data] print: stderr];
NSLog(@"popping list");
[[list front] print: stderr];
[list pop_front];
NSLog(@"printing list");
for(litr = [list begin]; ![litr equiv: [list end]]; [litr next])
[[litr data] print: stderr];
NSLog(@"deleting list");
while(![list empty]) [list pop_front];
NSLog(@"printing list");
for(litr = [list begin]; ![litr equiv: [list end]]; [litr next])
[[litr data] print: stderr];
NSLog(@"deleting list again");
while(![list empty]) [list pop_front];
NSLog(@"printing list again");
for(litr = [list begin]; ![litr equiv: [list end]]; [litr next])
[[litr data] print: stderr];
[pool drain];
return 0;
}
Mike 1234 Bill 3212 Sarah 1321 John 1021 Carol 3223 Debbie 4231 Gary 9321 Ann 1231 Dale 7231 Lynn 8133 Patty 9999
2013-01-22 14:33:57.347 main[87921:903] main start 2013-01-22 14:33:57.364 main[87921:903] printing list Mike 1234 Bill 3212 Sarah 1321 John 1021 Carol 3223 Debbie 4231 Gary 9321 Ann 1231 Dale 7231 Lynn 8133 Patty 9999 2013-01-22 14:33:57.364 main[87921:903] printing list Mike 1234 Bill 3212 Sarah 1321 John 1021 Carol 3223 Debbie 4231 Gary 9321 Ann 1231 Dale 7231 Lynn 8133 Patty 9999 2013-01-22 14:33:57.364 main[87921:903] popping list Mike 1234 2013-01-22 14:33:57.365 main[87921:903] printing list Bill 3212 Sarah 1321 John 1021 Carol 3223 Debbie 4231 Gary 9321 Ann 1231 Dale 7231 Lynn 8133 Patty 9999 2013-01-22 14:33:57.365 main[87921:903] deleting list 2013-01-22 14:33:57.366 main[87921:903] printing list 2013-01-22 14:33:57.366 main[87921:903] deleting list again 2013-01-22 14:33:57.367 main[87921:903] printing list again
tar.gz
archive of your lab12/ directory, including:
README
file containing
Makefile
.h
headers and .c
source)
make clean
before tar
)
submit
notes.