140 likes | 304 Views
Stack ADT & List Implementation http://www.cse.unt.edu/~Nielsen/1040/ ../~sweany/CSCE1040F13/Home.html. Nov 13, 2013 CSCE 1040: Computer Science II Rodney Nielsen. Midterm & Withdraw Date. Midterm Redo Done with practice questions. Major 3. Major 3 due before 11:55 pm, Nov 22
E N D
Stack ADT &List Implementationhttp://www.cse.unt.edu/~Nielsen/1040/../~sweany/CSCE1040F13/Home.html Nov 13, 2013 CSCE 1040: Computer Science II Rodney Nielsen
Midterm & Withdraw Date • Midterm Redo • Done with practice questions
Major 3 • Major 3 due before 11:55 pm, Nov 22 • Requires a completed and working Major 2 • Your choice • Get the solution to Major 2, or • Get extra credit toward Major 2 by completing Major 3 without the solution to Major 2 • Contact grader: SiamakJanmohammadi@my.unt.edu • Link to youtube video on the syllabus discussing how to convert an NFA to a DFA, removing epsilon transitions • http://www.youtube.com/watch?v=taClnxU-nao
Extra Credit 1 • Submit reports on bug resolution • What was the error message • Where did you try to find the solution • Were you successful • What was the bug • What was the solution
Extra Credit 2 • NAO robot programs • Get it to do anything interesting • Walk through a maze • Find a person • Move a game piece from one location to another • Recognize a long list of spoken names and say “Hello name!” • Recognize a person from a set of several people and recognize that a person is not in that group • Etc., etc. • nao.cse.unt.edu • Contact jimbglenn@gmail.com
Extra Credit 3 • Testing-related research • This will completely replace your lowest lab grade
Homework by 10:30a M 11/18 • list.c • Due Monday by class time • Implement a select the function prototypes in list.h • Base data type is a room visited in search and rescue • I will provide list.h, but you can add anything you like
Reading • Chapter 10 through 10.9 by Monday
Stack ADT – stack.h Data Type Defns #include <stdio.h> #include <stdlib.h> #define EMPTY 0 #define FULL 10000 typedef char Data; typedef enum {false, true} boolean; struct Elem { Data d; struct Elem* next; } typedef struct Elem Elem; struct Stack { int cnt; Elem* top; } typedef struct Stack Stack;
Stack ADT – stack.h Operations ... struct Stack { intcnt; Elem* top; } typedefstruct Stack Stack; void initialize(Stack* stk); void push(Datad, Stack* stk); Data pop(Stack* stk); Data top(Stack* stk); booleanempty(const Stack* stk); booleanfull(const Stack* stk);
Stack Impl – stack.cinitialize #include "stack.h” /* prototype: voidinitialize(Stack*stk); * struct Stack { * int cnt; * Elem* top; * } * / void initialize(Stack* stk) { stk -> cnt = 0; stk -> top = NULL; }
Stack Impl – stack.cpush #include "stack.h” ... void push(Data d, Stack* stk) { Elem* p; p = malloc(sizeof(Elem)); p -> d = d; p -> next = stk -> top; stk -> top = p; stk -> cnt++; }
Stack Impl – stack.cpop #include "stack.h” … Data pop(Stack* stk) { Data d; Elem* p; d = stk -> top -> d; p = stk -> top; stk -> top = stk -> top -> next; stk -> cnt--; free(p); return d; }
Stack Impl – stack.c #include "stack.h” … Data top(Stack* stk) { return (stk -> top -> d); } boolean empty(const Stack* stk) { return ((boolean) (stk -> cnt == EMPTY)); } boolean full(const Stack* stk) { return ((boolean) (stk -> cnt == FULL)); }