libcont/0040755000175000001440000000000007614713356012250 5ustar aediniususerslibcont/list/0040755000175000001440000000000007615041156013214 5ustar aediniususerslibcont/list/list.h0100644000175000001440000000074307604652573014352 0ustar aediniususers#ifndef LIST_H #define LIST_H #include @interface LinkedList : Object { id head, tail; int objectCount; } -init; -free; -(int)getObjectCount; -(id)getObjectAtIndex:(int)i; -(id)insertObject:(id)data atIndex:(int)i; -(id)appendObject:(id)data; -(id)prependObject:(id)data; -removeObjectAtIndex:(int)i; -(BOOL)isEmpty; // These are private methods; You should not be concerned with these. -(id)getNodeAtIndex:(int)i; -emptyList; // SO DON'T BE. @end #endif libcont/list/list.m0100644000175000001440000000750007615035241014342 0ustar aediniususers#include #include "list.h" #include "node.h" @implementation LinkedList -init { head = tail = nil; objectCount = 0; return self; } -free { [self emptyList]; return [super free]; } -(int)getObjectCount { return objectCount; /* int i=0; id tmp = head; while(tmp != tail) { tmp = [tmp getNext]; i++; } return i; */ } -(id)getNodeAtIndex:(int)i { id tmp = head; int k=0; while(tmp && (k0) return NO; else return YES; } -emptyList { int i; while(![self isEmpty]) { [self removeObjectAtIndex:0]; } return self; } @end libcont/list/node.h0100644000175000001440000000056007604652573014321 0ustar aediniususers#ifndef NODE_H #define NODE_H #include @interface Node : Object { id next, prev, data; } -init; -free; -(BOOL)isAttached; -(BOOL)isDoublyAttached; -(BOOL)isFrontlyAttached; -(BOOL)isRearlyAttached; -setNext:(id)new; -setPrevious:(id)new; -setData:(id)new; -(id)getNext; -(id)getPrevious; -(id)getData; -swapDataWithNode:(id)node; @end #endif libcont/list/node.m0100644000175000001440000000163207614701171014315 0ustar aediniususers#include "node.h" @implementation Node -init { next = prev = nil; } -free { next = prev = nil; [data free]; return [super free]; } -setData:(id)new { data = [new copy]; return self; } -(id)getData { return data; } -setNext:(id)new { next = new; return self; } -(id)getNext { return next; } -setPrevious:(id)new { prev = new; return self; } -(id)getPrevious { return prev; } -(BOOL)isAttached { if([self isFrontlyAttached] || [self isRearlyAttached]) return YES; else return NO; } -(BOOL)isDoublyAttached { if([self isFrontlyAttached] && [self isRearlyAttached]) return YES; else return NO; } -(BOOL)isFrontlyAttached { if(prev) return YES; else return NO; } -(BOOL)isRearlyAttached { if(next) return YES; else return NO; } -swapDataWithNode:(id)node { id tmp; tmp = [self getData]; [self setData:[node getData]]; [node setData:tmp]; tmp = nil; return self; } @end libcont/list/Makefile0100644000175000001440000000025107614657111014652 0ustar aediniususersOBJDIR=../obj all: list.o node.o list.o: list.m list.h cc -c list.m cp list.o $(OBJDIR) node.o: node.m node.h cc -c node.m cp node.o $(OBJDIR) clean: rm -rf *.o libcont/queue/0040755000175000001440000000000007615041156013365 5ustar aediniususerslibcont/queue/Makefile0100644000175000001440000000014707614657130015030 0ustar aediniususersOBJDIR=../obj all: queue.o queue.o: queue.m cc -c queue.m cp queue.o $(OBJDIR) clean: rm -rf *.o libcont/queue/queue.h0100644000175000001440000000025207604652573014667 0ustar aediniususers#ifndef QUEUE_H #define QUEUE_H #include "../list/list.h" @interface Queue : LinkedList { } -(id)getObject; -(id)enqueueObject:(id)obj; -dequeueObject; @end #endif libcont/queue/queue.m0100644000175000001440000000034207604652573014674 0ustar aediniususers#include "queue.h" @implementation Queue -(id)getObject { return [self getObjectAtIndex:0]; } -(id)enqueueObject:(id)obj { return [self appendObject:obj]; } -dequeueObject { return [self removeObjectAtIndex:0]; } @end libcont/stack/0040755000175000001440000000000007615041156013346 5ustar aediniususerslibcont/stack/Makefile0100644000175000001440000000014707614657143015015 0ustar aediniususersOBJDIR=../obj all: stack.o stack.o: stack.m cc -c stack.m cp stack.o $(OBJDIR) clean: rm -rf *.o libcont/stack/stack.h0100644000175000001440000000024307614711466014627 0ustar aediniususers#ifndef STACK_H #define STACK_H #include "../list/list.h" @interface Stack : LinkedList { } -(id)getObject; -(id)pushObject:(id)obj; -popObject; @end #endif libcont/stack/stack.m0100644000175000001440000000033407604652573014637 0ustar aediniususers#include "stack.h" @implementation Stack -(id)getObject { return [self getObjectAtIndex:0]; } -(id)pushObject:(id)obj { return [self prependObject:obj]; } -popObject { return [self removeObjectAtIndex:0]; } @end libcont/test/0040755000175000001440000000000007615041156013220 5ustar aediniususerslibcont/test/Makefile0100644000175000001440000000041007615040103014637 0ustar aediniususersall: list-test stack-test list-test: list-test.m cd .. && make all cc -o list-test -I../ -L../obj/ list-test.m -lcont -lobjc stack-test: stack-test.m cd .. && make all cc -o stack-test -I../ -L../obj/ stack-test.m data.m -lcont -lobjc clean: rm -rf *test libcont/test/list-test.m0100644000175000001440000000120507615035555015327 0ustar aediniususers#include #include #include "list/list.h" int main(void) { id list; int i; list = [[LinkedList alloc] init]; [list appendObject:@"you,"]; [list prependObject:@"i"]; [list insertObject:@"love" atIndex:1]; [list appendObject:@"jenn,"]; [list appendObject:@"my love"]; for(i=0;i<[list getObjectCount];i++) { printf("%s ",[[list getObjectAtIndex:i] cString]); } [list removeObjectAtIndex: [list getObjectCount]-1]; [list removeObjectAtIndex: 2]; printf("\n"); for(i=0;i<[list getObjectCount];i++) { printf("%s ",[[list getObjectAtIndex:i] cString]); } [list free]; printf("\n"); return 0; } libcont/test/data.h0100644000175000001440000000031107614711604014273 0ustar aediniususers#ifndef DATA_H #define DATA_H #include #include @interface Data : Object { long myData; } -init:(long)data; -free; -setData:(long)data; -(long)getData; @end #endif libcont/test/stack-test.m0100644000175000001440000000236307615041153015456 0ustar aediniususers#include #include #include #include "../stack/stack.h" #include "data.h" void getOperands(id stack, long operands[2]) { operands[0] = [[stack getObject] getData]; [stack popObject]; operands[1] = [[stack getObject] getData]; [stack popObject]; } int main(int argc, char *argv[]) { int i=1; long operands[2]; id stack, data; if(argc<2) { printf("Expression!!\n"); return 0; } stack = [[Stack alloc] init]; data = [[Data alloc] init]; while(argv[i]) { if(strcmp(argv[i], "+")==0) { getOperands(stack, operands); [data setData: operands[0] + operands[1]]; [stack pushObject: data]; } else if(strcmp(argv[i], "-") == 0) { getOperands(stack, operands); [data setData: operands[0] - operands[1]]; [stack pushObject: data]; } else if(strcmp(argv[i], "*") == 0) { getOperands(stack, operands); [data setData: operands[0] * operands[1]]; [stack pushObject: data]; } else if(strcmp(argv[i], "/") == 0) { getOperands(stack, operands); [data setData: operands[0] / operands[1]]; [stack pushObject: data]; } else { [data setData:atol(argv[i])]; [stack pushObject: data]; } i++; } printf("Remaining Value is %i.\n", [[stack getObject] getData]); [stack free]; } libcont/test/data.m0100644000175000001440000000035607614711701014307 0ustar aediniususers#include "data.h" @implementation Data -init:(long)data { [self setData:data]; return [super init]; } -free { return [super free]; } -setData:(long)data { myData = data; return self; } -(long)getData { return myData; } @end libcont/obj/0040755000175000001440000000000007615041156013013 5ustar aediniususerslibcont/obj/Makefile0100644000175000001440000000022507614657421014456 0ustar aediniususersall: libcont.a libcont.so libcont.a: ar r libcont.a *.o libcont.so: gcc -shared -o libcont.so *.o clean: rm -rf *.o rm -rf libcont.a libcont.so libcont/Makefile0100644000175000001440000000055607614657314013714 0ustar aediniususersall: list-files stack-files queue-files cd obj && make all list-files: cd list && make all stack-files: cd stack && make all queue-files: cd queue && make all clean: clean-list clean-stack clean-queue cd obj && make clean cd test && make clean clean-list: cd list && make clean clean-stack: cd stack && make clean clean-queue: cd queue && make clean