final solutions

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

Info icon This 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) {
Image of page 1

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern