User Tools

Site Tools


user:nbrimme1:portfolio:dataproject3

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/perform this project, the listed resources/experiences need to be consulted/achieved:

  • 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:

  1. dll.h: This is the header file. Everything before main() is included in this header file. Examples are #include's, #defines, struct definitions, and function prototypes.
  2. main.c: This is the main C program. It only includes everything between int main(){ }; (i.e. the menu).
  3. listOps.c: This file contains only the list operations (create(), build(), insert(), append(), remove(), sort(), and clear()).
  4. display.c: This C file contains only the display functions (displayF() and displayB()).

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:

lab46:~/src/data/dll$ cp dll.c dll.h
lab46:~/src/data/dll$ cp dll.c main.c
lab46:~/src/data/dll$ cp dll.c listOps.c
lab46:~/src/data/dll$ cp dll.c display.c

After editing the 4 separate files;

#include <“dll.h”>

was added to the top of all the C files (except the header file). This will include the DLL.h header file in the separate .c files, as headers for those files. Next, the new .c files were compiled into object files (The header file is NOT included):

lab46:~/src/data/dll$ gcc -c listOps.c  ->  listOps.o
lab46:~/src/data/dll$ gcc -c display.c  ->  display.o
lab46:~/src/data/dll$ gcc -c main.c     ->  main.o

Then the separate object files were then compiled into 1 executable:

lab46:~/src/data/dll$ gcc -o dlinklist main.o listOps.o display.o

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 <code> </code> blocks here.

dll.h: This is the header file. Everything before main() is included in this header file. Examples are #include's, #defines, struct definitions, and function prototypes.

/*
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 <stdio.h>
#include <stdlib.h>
 
// 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).

/*
Nicholas Brimmer
Data Structures
Mathew Haas
Spring 2013
Doubly Linked List main.c File.
*/
 
/* Main menu. Initialize "Node" to NULL.
i = input for the switch statement. */
Node *list = NULL;
int input = 0;
 
while (input != 'Q')
{
  printf("\n");
  printf("Generate a Doubley Linked List Operations.");
  printf("B. Build a Doubly Linked List.");
  printf("C. Create a Node.");
  printf("I. Insert a Node.");
  printf("A. Append a Node.");
  printf("R. Remove a Node.");
  printf("F. Display the list Forward.");
  printf("B. Display the list Backward.");
  printf("S. Sort the List.");
  printf("E. Clear the List.");
  printf("Q. Quit.");
  printf("Selection: ");
  scanf("%d", &input);
  printf("\n")
 
  switch (input)
  {
    case 'B':
      break;
 
    case 'C':
      break;
 
    case 'I':
      break;
 
    case 'A'
      break;
 
    case 'R'
      break;
 
    case 'F'
      break;
 
    case 'B'
      break;
 
    case 'S'
      break;
 
    case 'C'
      break;
 
    case 'Q'
      break;  


listOps.c: This file contains only the list operations (create(), build(), insert(), append(), remove(), sort(), and clear()).

/*
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 "NULL" at the beginning of the list.
  printf("NULL\n");
 
  while (tmp->next != NULL)
  {
    printf("[%d] %d -> ", i, tmp->value);
    tmp = tmp->next;
  }
 
 
  // Print "NULL" at the end of the list.
  printf("NULL\n");
 
  return (list);
}


display.c: This C file contains only the display functions displayF() and displayB().

/*
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->next;
 
    // Set *end pointer.
    if (tmp->next == NULL)
    {
      tmp = *end
    }
}

Execution

Again, if there is associated code with the project, and you haven't already indicated how to run it, provide a sample run of your code:

lab46:~/src/cprog$ ./hello
Hello, World!
lab46:~/src/cprog$ 

Reflection

Comments/thoughts generated through performing the project, observations made, analysis rendered, conclusions wrought. What did you learn from doing this project?

References

In performing this project, the following resources were referenced:

Back to my Portfolio
Back to my Opus

user/nbrimme1/portfolio/dataproject3.txt · Last modified: 2013/11/29 18:35 by nbrimme1