This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
user:nbrimme1:portfolio:dataproject3 [2013/11/29 07:39] – [Code] nbrimme1 | user:nbrimme1:portfolio:dataproject3 [2013/11/29 18:35] (current) – [Code] nbrimme1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======Data Project 3: Doubly Linked List====== | ||
+ | A project for COURSENAME by YOUR NAME OR GROUPMEMBER NAMES during the SEMESTER YEAR. | ||
+ | |||
+ | This project was begun on DATE and is anticipated to take X AMOUNT OF TIME. (Upon completion you can correct this with the actual length). | ||
+ | |||
+ | =====Objectives===== | ||
+ | State the purpose of this project. What is the point of this project? What do we hope to accomplish by undertaking it? | ||
+ | =====Prerequisites===== | ||
+ | In order to successfully accomplish/ | ||
+ | |||
+ | * resource1 | ||
+ | * resource2 | ||
+ | * resource3 | ||
+ | * experience1 | ||
+ | * experience2 | ||
+ | * etc. | ||
+ | |||
+ | =====Background===== | ||
+ | State the idea or purpose of the project. What are you attempting to pursue? | ||
+ | |||
+ | Upon approval, you'll want to fill this section out with more detailed background information. DO NOT JUST PROVIDE A LINK. | ||
+ | |||
+ | Providing any links to original source material, such as from a project page, is a good idea. | ||
+ | |||
+ | You'll want to give a general overview of what is going to be accomplished (for example, if your project is about installing a web server, do a little write-up on web servers. What is it, why do we need one, how does it work, etc.) | ||
+ | |||
+ | This program will generate a Doubly Linked List. A Doubly Linked List is similar to a Singly Linked List; except with *prev and *next pointers instead of just a *next pointer. | ||
+ | =====Scope===== | ||
+ | Give a general overview of your anticipated implementation of the project. Address any areas where you are making upfront assumptions or curtailing potential detail. State the focus you will be taking in implementation. | ||
+ | |||
+ | =====Attributes===== | ||
+ | State and justify the attributes you'd like to receive upon successful approval and completion of this project. | ||
+ | |||
+ | * attribute1: why you feel your pursuit of this project will gain you this attribute | ||
+ | * attribute2: why you feel your pursuit of this project will gain you this attribute | ||
+ | * etc... | ||
+ | |||
+ | =====Procedure===== | ||
+ | The actual steps taken to accomplish the project. Include images, code snippets, command-line excerpts; whatever is useful for intuitively communicating important information for accomplishing the project. | ||
+ | |||
+ | First, the program was written as 1 single C program, **dll.c**. Then **dll.c** was split into multiple object files, each with its own purpose. The object files are then compiled into a library where it's functions can be used by other programs: | ||
+ | - **dll.h:** This is the header file. Everything before main() is included in this header file. Examples are # | ||
+ | - **main.c:** This is the main C program. It only includes everything between int main(){ }; (i.e. the menu). | ||
+ | - **listOps.c: | ||
+ | - **display.c: | ||
+ | //**Note:** The **main.c** file isn't included in the library because **main.c** is the main program and will use the library.// | ||
+ | |||
+ | To split up **dll.c** into separate files; **dll.c** was copied into 4 separate .C files, then they were all edited: | ||
+ | <cli> | ||
+ | lab46: | ||
+ | lab46: | ||
+ | lab46: | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | After editing the 4 separate files; <code c># | ||
+ | <cli> | ||
+ | lab46: | ||
+ | lab46: | ||
+ | lab46: | ||
+ | </ | ||
+ | Then the separate object files were then compiled into 1 executable: | ||
+ | <cli> | ||
+ | lab46: | ||
+ | </ | ||
+ | The order of the object files can sometimes be important to the compiler. You do not include the header file at compile time, it is included in the 3 .c files. | ||
+ | =====Code===== | ||
+ | Upon completion of the project, if there is an applicable collection of created code, place a copy of your finished code within < | ||
+ | |||
+ | **dll.h:** This is the header file. Everything before main() is included in this header file. Examples are # | ||
+ | <code c> | ||
+ | /* | ||
+ | Nicholas Brimmer | ||
+ | Data Structures | ||
+ | Mathew Haas | ||
+ | Spring 2013 | ||
+ | Doubly Linked List program Header File. | ||
+ | */ | ||
+ | |||
+ | // Include header file. | ||
+ | // If not defined. | ||
+ | #ifndef _DLLLIB_H | ||
+ | // Define. | ||
+ | #define _DLLLIB_H | ||
+ | |||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | // Node structure | ||
+ | struct node { | ||
+ | // Value inside node. | ||
+ | int value; | ||
+ | // Pointer to the next node. | ||
+ | struct node *next; | ||
+ | // Pointer to the previous node. | ||
+ | struct node *prev; | ||
+ | }; | ||
+ | typedef struct node Node; | ||
+ | |||
+ | |||
+ | int createList(); | ||
+ | void buildList(); | ||
+ | int insert(); | ||
+ | int append(); | ||
+ | int removeNode(); | ||
+ | int displayListF(); | ||
+ | int displayListB(); | ||
+ | void sortList(); | ||
+ | int clearList(); | ||
+ | |||
+ | int input | ||
+ | |||
+ | /* | ||
+ | *beg points to the beginning of the list | ||
+ | *end points to the end of the lust. | ||
+ | *tmp and *tmp2 are used to compare values when sorting. | ||
+ | */ | ||
+ | Node *beg, *end, *tmp, *tmp2; | ||
+ | </ | ||
+ | |||
+ | **main.c:** This is the main C program. It only includes everything between int main(){ }; (i.e. the menu). | ||
+ | <code c> | ||
+ | /* | ||
+ | Nicholas Brimmer | ||
+ | Data Structures | ||
+ | Mathew Haas | ||
+ | Spring 2013 | ||
+ | Doubly Linked List main.c File. | ||
+ | */ | ||
+ | |||
+ | /* Main menu. Initialize " | ||
+ | i = input for the switch statement. */ | ||
+ | Node *list = NULL; | ||
+ | int input = 0; | ||
+ | |||
+ | while (input != ' | ||
+ | { | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | printf(" | ||
+ | scanf(" | ||
+ | printf(" | ||
+ | | ||
+ | switch (input) | ||
+ | { | ||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | | ||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | |||
+ | case ' | ||
+ | break; | ||
+ | </ | ||
+ | |||
+ | **listOps.c: | ||
+ | <code c> | ||
+ | /* | ||
+ | Nicholas Brimmer | ||
+ | Data Structures | ||
+ | Mathew Haas | ||
+ | Spring 2013 | ||
+ | Doubly Linked List List Operations File. | ||
+ | */ | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | // Display List Forward: | ||
+ | Node *displayListF(Node *list) | ||
+ | { | ||
+ | // i is an iterator. | ||
+ | int i = 0; | ||
+ | // Initialize pointer tmp to NULL. | ||
+ | Node *tmp = NULL; | ||
+ | |||
+ | // Reset tmp to the start of the list. | ||
+ | tmp = *start; | ||
+ | |||
+ | // Print " | ||
+ | printf(" | ||
+ | |||
+ | while (tmp-> | ||
+ | { | ||
+ | printf(" | ||
+ | tmp = tmp-> | ||
+ | } | ||
+ | |||
+ | |||
+ | // Print " | ||
+ | printf(" | ||
+ | |||
+ | return (list); | ||
+ | } | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | </ | ||
+ | |||
+ | **display.c: | ||
+ | <code c> | ||
+ | /* | ||
+ | Nicholas Brimmer | ||
+ | Data Structures | ||
+ | Mathew Haas | ||
+ | Spring 2013 | ||
+ | Doubly Linked List program display.c File. | ||
+ | */ | ||
+ | |||
+ | // Set *beg and *end; Pointers to beginning and end of list. | ||
+ | // Set *beg to tmp before tmp is iterated through the list. | ||
+ | tmp = *beg; | ||
+ | |||
+ | // Iterate through the list for *end. | ||
+ | while (tmp != NULL) | ||
+ | { | ||
+ | tmp = tmp-> | ||
+ | |||
+ | // Set *end pointer. | ||
+ | if (tmp-> | ||
+ | { | ||
+ | tmp = *end | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | =====Execution===== | ||
+ | Again, if there is associated code with the project, and you haven' | ||
+ | |||
+ | <cli> | ||
+ | lab46: | ||
+ | Hello, World! | ||
+ | lab46: | ||
+ | </ | ||
+ | |||
+ | =====Reflection===== | ||
+ | Comments/ | ||
+ | |||
+ | =====References===== | ||
+ | In performing this project, the following resources were referenced: | ||
+ | |||
+ | * **[[http:// | ||
+ | |||
+ | [[http:// | ||
+ | [[http:// |