1 / 8

Linked Lists and Templates

Learn about destructors, pointers, linked lists, the difference between a stack and a queue, and recursion. Create and manipulate linked lists, explore storing different types of data, and understand templates.

ksusan
Download Presentation

Linked Lists and Templates

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Linked Lists and Templates But first: quiz results!

  2. Quiz results • What is a destructor? • What is a pointer? • What is a linked list • What is the difference between a stack and a queue? • What is recursion?

  3. Linked list reminder • What is a linked list? • What do we need to write to create a linked list?

  4. Linked List Node • Let's go ahead and create a linked list node • Named LLNode • Members: • pointer to next node named 'node' • data to be stored of type double named 'data'

  5. Linked List class • Let's make a linked list class named 'List': • constructor: initialize to an empty list • destructor: just ignore it for now • void add(double value): add an element to the front of the list • double front(): returns the first element in the list. You can assume the list has at least one element • member variable 'head' that points to the head of the list • And let's put all of the code in the header file

  6. Example main List lst; lst.add(3.14); cout << lst.front(); lst.add(6.02); cout << lst.front();

  7. Storing other types of data • Let's say we wanted to make a linked list of chars instead • What would we need to change?

  8. Templates • Templates allow us to give the C++ compiler a pattern to follow to make classes or structs that work with many different types of objects. • We can make our linked list templated so that users will be able to choose what type of linked list they want • Let's see what we'd need to change...

More Related