/*
 * Faculty of Applied Science and Engineering, University of Toronto
 * CSC181: Introduction to Computer Programming, Fall 2000
 *
 * Practical: 3
 * File: p03.c
 * Contains: Starter code for Practical 3.
 */

#include <stdio.h>
#include <assert.h>
#include <stdlib.h>

/*
 * Represents a node in a singly-linked list.
 */
struct listnode {
	int data;
	struct listnode* next;
};
typedef struct listnode ListNode;
typedef ListNode* ListNodePtr;

/*
 * Represents a sorted list. Implemented using a singly-linked list.
 */
struct sortedlist {
	struct listnode* front;
};
typedef struct sortedlist SortedList;
typedef SortedList* SortedListPtr;

/* Returns an empty list. */
SortedListPtr slInit(void) {
	SortedListPtr result = malloc(sizeof(SortedList));
	result->front = NULL;
	return result;
}

/* Prints out the contents of list l. */
void slPrint(SortedListPtr l) {
	ListNodePtr current = l->front;

	printf("{");
	if (current != NULL) {
		printf("%d", current->data);
		while (current->next != NULL) {
			current = current->next;
			printf(", %d", current->data);
		}
	}
	printf("}\n");
}

/* Inserts integer d into the sorted list l. */
void slInsert(SortedListPtr l, int d) {
	/* FIXME */
}

/* Removes the range of integers >= lower and <= upper from list l. */
void slDeleteRange(SortedListPtr l, int lower, int upper) {
	/* FIXME */
}

/* A small program to test the SortedList functions. */
int main(void) {
	SortedListPtr l = slInit();
	slPrint(l);
	slInsert(l, 6);
	slInsert(l, 8);
	slInsert(l, 10);
	slInsert(l, 4);
	slInsert(l, 2);
	slPrint(l);
	slDeleteRange(l, 3, 7);
	slPrint(l);
	return 0;
}
