All pastes #984324 Raw Edit

Unnamed

public text v1 · immutable
·published 2008-04-14 02:57 UTC
rendered paste body
// Jesse DeRose
// jderose
// PA2

#include <stdio.h>

#include "List.h"


typedef struct Node *NodeRef;

struct List{
	NodeRef first;
	NodeRef last;
	NodeRef current;
	int length;
}


struct Node{
	// Fields
	int data;
	NodeRef prev;
	NodeRef next;
}


/*** Constructors-Destructors ***/

// Returns a ListRef which points to a new empty list.
ListRef newList();

// Frees all heap memory associated with its
// ListRef* argument, and sets *pL to NULL.
void freeList(ListRef* pL);

/*** Access functions ***/

// Returns true if this List is empty, false otherwise.
int isEmpty(ListRef L);

// Returns true if current is undefined.
int offEnd(ListRef L);

// Returns true if first element is current. Pre: !isEmpty().
int atFirst(ListRef L);

// Returns true if last element is current. Pre: !isEmpty().
int atLast(ListRef L);

// Returns first element. Pre: !isEmpty().
int getFirst(ListRef L);

// Returns last element. Pre: !isEmpty().
int getLast(ListRef L);

// Returns current element. Pre: !isEmpty(), !offEnd().
int getCurrent(ListRef L);

// Returns current element. Pre: !isEmpty(), !offEnd().
int getLength(ListRef L);

// Returns true if this List has same elements as L in the
// same order. Ignores the current marker in both Lists.
int equals(ListRef A, ListRef B);

/*** Manipulation procedures ***/

// Sets this List to the empty state. Post: isEmpty().
void makeEmpty(ListRef L);

// Sets current marker to first element.
// Pre: !isEmpty(); Post: !offEnd().
void moveFirst(ListRef L);

// Sets current marker to last element
// Pre !isEmpty(); Post: !offEnd().
void moveLast(ListRef L);

// Moves current marker one step toward first element.
// Pre: !isEmpty(), !offEnd().
void movePrev(ListRef L);

// Moves current marker one step toward last element.
// Pre: !isEmpty(), !offEnd().
void moveNext(ListRef L);

// Inserts new element before first element.
// Post: !isEmpty().
void insertBeforeFirst(ListRef L, int data);

// Inserts new element after last element.
// Post: !isEmpty().
void insertAfterLast(ListRef L, int data);

// Inserts new element before current element.
// Pre: !isEmpty(), !offEnd().
void insertBeforeCurrent(ListRef L, int data);

// Inserts new element after current element.
// Pre: !isEmpty(), !offEnd().
void insertAfterCurrent(ListRef L, int data);

// Deletes first element. Pre: !isEmpty().
void deleteFirst(ListRef L);

// Deletes last element. Pre: !isEmpty().
void deleteLast(ListRef L);

// Deletes current element.
// Pre: !isEmpty(), !offEnd(); Post: offEnd()
void deleteCurrent(ListRef L);

/*** Other operations ***/

// Prints the List L to the file pointed to by out,
// formated as a space-separated string. This function plays
// roughly the same role as the "toString" function in Java.
void printList(FILE* out, ListRef L);

// Returns a new list which contains the same elements as this List, and
// in the same order. The current marker in the new list is undefined,
// regardless of the state of the current marker in this list. The state
// of this list is unchanged.
ListRef copyList(ListRef L);

// Returns a new List which is the concatenation of this list
// followed by L. The current marker in the new list is undefined,
// regardless of the states of the current markers in the two lists.
// The states of the two Lists are unchanged.
ListRef catList(ListRef A, ListRef B);