User Tools

Site Tools


user:nbrimme1:portfolio:dataproject5

Data Project 5: Queue

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.)

I have had previous experience with Queues from a different program at another college. They are also very similar to stacks; the only difference being where you push and pop values. It should be a simple exercise converting the Stack code that Matt gave us into a Queue.

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.

Again, I have had previous experience with both Stacks and Queues from a different program at another college. Also, Matt provided almost all of the code needed for the stack; making the implementation simple. A Queue is the same as a stack except you Enqueue (push) values to the end of the Queue and Dequeue (pop) values from the beginning of the Queue.

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.

Code

The same header files (Provided by Matt) used for the Stack can also be used for the Queue. This is because the only difference between a Stack and a Queue is where the data is pushed/popped. The required header files were also copied to the same directory.

node.h

/* If not defined. Prevents the header file from
being declared twice. */
#ifndef _NODE_H
#define _NODE_H
 
#include <stdlib.h>
 
struct node {
	// Pointer to next node.
	struct node *next;
	// Pointer to previous node.
	struct node *prev;
	// Value inside node.
	int value;
};
typedef struct node Node;
 
// "Make" a new node; passing an integer as its value.
Node *mknode(int);
// "Remove" a node; passing a pointer to a pointer to the node being removed.
void  rmnode(Node **);
// "Copy" a node; passing a pointer to the node being copied.
Node *cpnode(Node *);
 
#endif


list.h

/* If not defined. Prevents the header file from
being declared twice. */
#ifndef _LIST_H
#define _LIST_H
 
#include "node.h"
 
struct list {
	Node *start;
	Node *end;
	int qty;
};
typedef struct list List;
 
List *mklist();
List *insert(List *, Node *, Node *);
List *append(List *, Node *, Node *);
List *removeNode(List *, Node **);
void displayf(List *);
void displayb(List *);
List *clearlist(List *);
List *sortlist(List *);
 
#endif


queue.h:

#ifndef _QUEUE_H
#define _QUEUE_H
 
#include "list.h"
 
struct queue {
	// Pointer to the data in the list.
	List *data;
	// Pointer to the front of the Queue; Dequeue from the front.
	Node *front;
	// Pointer to the back of the Queue; Enqueue from the back.
	Node *back;
	// Size of the Queue.
	int bufsize;
};
typedef struct queue Queue;
 
// "make" a new Queue; passing an integer for the new node.
Queue *mkqueue(int);
// "Enqueue" a node, passing a value (Enqueue from back).
Queue *enqueue(Queue *, Node *);
// "Dequeue" a node, passing a double pointer to a node (Dequeue from front).
Node  *dequeue(Queue **);
 
#endif


mkqueue.c

#include "queue.h"
#include <stdio.h>
 
// "bufsize" is the size of the Queue (the "buffer").
Queue *mkqueue(int bufsize)
{
	/* myQueue used because myStack was used for the stack.
	Why change what works. */
	Queue *myQueue;
	myQueue = (Queue*)malloc(sizeof(Queue));
	// Call mklist(); from "list.h".
	myQueue->data = mklist();
	// Size of the Queue.
	myQueue->bufsize = bufsize;
	// The front and back pointers are NULL in a Queue with 1 node.
	myQueue->front = NULL;
	myQueue->back = NULL;
 
return(myQueue);
}


enqueue.c MISSING SOMETHING

#include "queue.h"
#include <stdio.h>
 
Queue *enqueue(Queue *myQueue, Node *newNode)
	{
		// Set Queue's *back pointer to *end of list.
		myQueue->back = myQueue->data->end;
		// Set Queue's *front pointer to *start of list.
		myQueue->front = myQueue->data->start;
	}
 
return(myQueue);
}


dequeue.c

// Add code here.

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:

  • URL1
  • URL2
  • URL3 (provides useful information on topic)
  • URL4

Back to my Portfolio
Back to my Opus

user/nbrimme1/portfolio/dataproject5.txt · Last modified: 2013/12/13 14:39 by nbrimme1