CS 24000 Lecture Notes - Lecture 21: C String Handling, Linked List, Sentinel Node

75 views2 pages

Document Summary

#define dlist_h struct dlistnode{ char * name; void * value; struct dlistnode * next; struct dlistnode * previous; class dlist { int nelements; Dlist(); void print(void); void addfront(char * name, void * value); void * lookup(char * name); int removefront(char * name); // but simplifies the list implementation. head = new dlistnode(); nelements = 0; head->next = head; head->previous = head; Implementing a double-linked list void dlist::addfront(char * name, void * value) { Dlistnode * e = new dlistnode(); e->name = strdup(name); e->value = value; //add at the beginning e->next = head->next; e->previous = head; e->next->previous = e; e->previous->next = e; nelements++; Implementing a double-linked list void dlist::addend(char * name, void * value) { Dlistnode * e = new dlistnode(); e->name = strdup(name); e->value = value; e->next = head; e->prev = head->prev; head->prev->next = e; head->prev=e; nelements++; Dlistnode * e = head->next; while (e!= head) if (!strcmp(e->name,name)) return e->value; e = e->next; return null;

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents