04LinkedLists - CS 240 Chapter 4 - Linked Lists CS 240...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 240 Chapter 4 - Linked Lists CS 240 Chapter 4 - Linked Lists 1Page 1 Static Array Chapter 4 Linked Lists Recall that linked lists enable us to dynamically adjust the size of a list, eliminating the need to preallocate a specific amount of memory. Preallocation Required! Wasteful if you allocate too much! Potentially fatal if you allocate too little! Dynamic Array Determine the size of the list before allocating memory! Not dynamic enough you cant change the size once its been decided! Linked List Completely dynamic! No space is wasted due to excess allocation! Additional space is allocated as needed! CS 240 Chapter 4 - Linked Lists CS 240 Chapter 4 - Linked Lists 2Page 2 Lets review linked lists with a little example that also refreshes our memory (so to speak) about recursion. In this example, were going to read text from an input file, keeping track of how many times each word is used in the text. Each node in the linked list will require a string field (to hold the word), an integer field (to hold the count), and a pointer field (to point to the next node). string word int count ptr next CS 240 Chapter 4 - Linked Lists CS 240 Chapter 4 - Linked Lists 3Page 3 When a word is inserted in the list, the list is traversed to see if the words already there... yadda 4 wassup 3 groovy 2 groovy yadda 4 groovy 3 wassup 3 yadda 4 groovy 3 wassup 3 oops 1 oops If the word is found, its node is removed, its count is incremented, and the node is reinserted to preserve the count/alphabetical ordering... If the word isnt found, a new node is created with a count of one, and inserted appropriately... CS 240 Chapter 4 - Linked Lists CS 240 Chapter 4 - Linked Lists 4Page 4 Desired linked list functionality: Default Constructor Copy Constructor INSERT member function RETRIEVE member function Destructor GETNODE member function Input (>>) friend operator Output (<<) friend operator Recursive Find function Recursive Insert function Recursive Output function Unpunctuate & upper-case function Make an empty list Make a deep copy list Delete all list nodes Insert a new(?) word Find a words count Create word/count node Read a text file Write word/count list Find a word Insert a word Write a word/count Edit a word CS 240 Chapter 4 - Linked Lists CS 240 Chapter 4 - Linked Lists 5Page 5 ///////////////////////////////////////// // Class definition file: linkedList.h // // // // Each node in a LinkedList will have // // two components: an elementType (a // // string representing a word and an...
View Full Document

This note was uploaded on 08/26/2009 for the course CS 240 taught by Professor Klein,s during the Spring '08 term at Southern Illinois University Edwardsville.

Page1 / 16

04LinkedLists - CS 240 Chapter 4 - Linked Lists CS 240...

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

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