CGS 3460 Assignment 9: Implementing a Double-Ended Queue (DEQUE) in C, Assignments of Computer Science

Instructions for assignment 9 in the cgs 3460 - programming using c course, where students are required to implement a double-ended queue (deque) data structure using c. The deque should contain integers with no size limit, and students must define functions to add and remove elements from the front and back of the queue. The document also includes instructions for submitting the assignment.

Typology: Assignments

Pre 2010

Uploaded on 09/17/2009

koofers-user-g1o
koofers-user-g1o 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CGS 3460 - Programming Using C
Summer 2009
Assignment #9
20 Points
Assigned: 07/24/2009, Friday
Due: 07/30/2009, Thu, 11:59 PM
For this assignment, there is a single project. We will being implementing an abstract
data type known as a double ended queue(DEQUE). You may want to check out
http://en.wikipedia.org/wiki/Double-ended_queue for more information on the DEQUE.
Also note that the implementation of a similar abstract data type, known as a stack is
discussed in the book in chapter 19.
The DEQUE will contain integers and have no limit on the size. You will define your
DEQUE in files called deque.h and deque.c. All variables used should be accessible only
to functions defined in deque.c.(i.e., we should not be able to access any of your
variables in main.)
The following functions should be defined so that we can modify the DEQUE from main.
They should be declared in deque.h and defined in deque.c. You may add any additional
“helper” functions you wish, however, we should not be able to call your helper functions.
Note that limiting access to a variable or a function in your deque.c file is as simple as
applying a certain key word.
void addToFront(int v); - Adds the given value to the front of the queue. Note, if you
decide to use a dynamic array to keep track of the elements in your DEQUE and the
number of elements in your DEQUE becomes larger than the array size, you will need to
create a new array that is large enough to hold the number of elements in your queue,
copy the elements from the old array to the new one, and use the new array to hold the
elements.
void addToBack(int v); - Adds the given value to the back of the queue. Note, if you
decide to use a dynamic array to keep track of the elements in your DEQUE and the
number of elements in your DEQUE becomes larger than the array size, you will need to
create a new array that is large enough to hold the number of elements in your queue,
copy the elements from the old array to the new one, and use the new array to hold the
elements.
int removeFromFront(); - Removes the element at the front of the queue and returns
it. If the DEQUE is empty, it returns -1.
int removeFromBack(); - Removes the element at the back of the queue and returns it.
If the DEQUE is empty, it returns -1.
int checkFront(); - Returns the element at the front of the queue, but does not remove
it. If the DEQUE is empty, it returns -1.
int checkBack(); -Returns the element at the back of the queue, but does not remove it.
If the DEQUE is empty, it returns -1.
pf2

Partial preview of the text

Download CGS 3460 Assignment 9: Implementing a Double-Ended Queue (DEQUE) in C and more Assignments Computer Science in PDF only on Docsity!

CGS 3460 - Programming Using C

Summer 2009

Assignment # 20 Points Assigned: 07/24/2009, Friday Due: 07/30/2009, Thu, 11:59 PM For this assignment, there is a single project. We will being implementing an abstract data type known as a double ended queue(DEQUE). You may want to check out http://en.wikipedia.org/wiki/Double-ended_queue for more information on the DEQUE. Also note that the implementation of a similar abstract data type, known as a stack is discussed in the book in chapter 19. The DEQUE will contain integers and have no limit on the size. You will define your DEQUE in files called deque.h and deque.c. All variables used should be accessible only to functions defined in deque.c.(i.e., we should not be able to access any of your variables in main.) The following functions should be defined so that we can modify the DEQUE from main. They should be declared in deque.h and defined in deque.c. You may add any additional “helper” functions you wish, however, we should not be able to call your helper functions. Note that limiting access to a variable or a function in your deque.c file is as simple as applying a certain key word. void addToFront(int v); - Adds the given value to the front of the queue. Note, if you decide to use a dynamic array to keep track of the elements in your DEQUE and the number of elements in your DEQUE becomes larger than the array size, you will need to create a new array that is large enough to hold the number of elements in your queue, copy the elements from the old array to the new one, and use the new array to hold the elements. void addToBack(int v); - Adds the given value to the back of the queue. Note, if you decide to use a dynamic array to keep track of the elements in your DEQUE and the number of elements in your DEQUE becomes larger than the array size, you will need to create a new array that is large enough to hold the number of elements in your queue, copy the elements from the old array to the new one, and use the new array to hold the elements. int removeFromFront(); - Removes the element at the front of the queue and returns it. If the DEQUE is empty, it returns -1. int removeFromBack(); - Removes the element at the back of the queue and returns it. If the DEQUE is empty, it returns -1. int checkFront(); - Returns the element at the front of the queue, but does not remove it. If the DEQUE is empty, it returns -1. int checkBack(); - Returns the element at the back of the queue, but does not remove it. If the DEQUE is empty, it returns -1.

Instructions for submitting Assignment 9

  1. First compress your program files into a tar file. For this, change to the directory where you have stored both the files. At the terminal command prompt (putty, Linux console, MAC terminal, etc.) type: tar cvf assign9.tar deque.h deque.c Let’s say you have stored your files in assign8 directory on your “rain” machine.

cd assign ls main.c deque.h deque.c .. tar cvf assign9.tar deque.h deque.c ls main.c deque.h deque.c assign9.tar ….

  1. If you are working from Windows platform using Putty and WinSCP, you can create a directory assign9 in your home directory on rain machine using putty. Create the directory using this command on putty

    cd //to change to the home directory mkdir assign9 //to create the directory under home directory

  2. Then transfer deque.h and deque.c to assign9 directory on rain using WinSCP.
  3. Go to step 1 to tar the file using putty.
  4. Use WinSCP to copy assign9.tar from rain machine back to your local computer, say desktop.
  5. Upload the assign9.tar to WebCT.
  6. Please check the discussion page for assignment 9 on WebCT for common questions and their answers.