final solutions

final solutions - DLList.cpp#include #include...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
DLList.cpp #include <string.h> #include <stdlib.h> #include "DLList.h" // Constructor DLList::DLList() { // Create Sentinel node. This node does not store any data // but simplifies the list implementation. head = new DLListEntry(); head->next = head; head->previous = head; } // Adds new name, value pair at the end of the list. // If name already exists substitute value in that entry and return 1. Otherwise return 0 int DLList::add(char * name, char * value) { DLListEntry * e; e = head->next; // Try to find if entry is already there while (e!=head) { if (!strcmp(e->name,name)) { // Entry found. Substitute value free(e->value); e->value = strdup(value); return 1; } e = e->next; } // Entry not found. Add new entry at the end of the list e = new DLListEntry; e->name = strdup(name); e->value = strdup(value); //Add at the beginning e->next = head; e->previous = head->previous; head->previous = e; e->previous->next = e; return 0; } // Removes node from the list with that name. Return 0 if nde does not exist. int DLList::remove(char * name) { DLListEntry * e; e = head->next; // Try to find if entry is already there while (e!=head) {
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
if (!strcmp(e->name,name)) { // Entry found. break;
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 02/18/2012 for the course CS 240 taught by Professor Rego during the Fall '08 term at Purdue.

Page1 / 5

final solutions - DLList.cpp#include #include...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online