Linked Lists b - UAH CPE 212 Fundamentals of Software...

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

View Full Document Right Arrow Icon
UAH CPE 212 Fundamentals of Software Engineering Agenda Class 11 Linked Lists 2 Linked Lists Application Key Concepts
Background image of page 1

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

View Full DocumentRight Arrow Icon
UAH CPE 212 Today Last Time First Fundamental Structure, Linked Lists This Time Bagged Again
Background image of page 2
UAH CPE 212 Linked List For Bag #ifndef LINK1_H #define LINK1_H #include <stdlib.h> // Provides size_t struct Node { typedef double Item; Item data; Node *link; }; // FUNCTIONS for the linked list toolkit size_t list_length(Node* head_ptr); void list_head_insert(Node*& head_ptr, const Node::Item& entry); void list_insert(Node* previous_ptr, const Node::Item& entry); Node* list_search(Node* head_ptr, const Node::Item& target); Node* list_locate(Node* head_ptr, size_t position); void list_head_remove(Node*& head_ptr); void list_remove(Node* previous_ptr); void list_clear(Node*& head_ptr); void list_copy(Node* source_ptr, Node*& head_ptr, Node*& tail_ptr); void list_piece(Node* start_ptr, Node* end_ptr, Node*& head_ptr, Node*& tail_ptr); #endif
Background image of page 3

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

View Full DocumentRight Arrow Icon
UAH CPE 212 Bag 3 #ifndef BAG_H #define BAG_H #include <stdlib.h> // Provides size_t and NULL #include "link1.h" // Provides Node struct class Bag { public: // TYPEDEF typedef Node::Item Item; // CONSTRUCTORS and DESTRUCTOR Bag( ); Bag(const Bag& source); ~Bag( ); // MODIFICATION functions void insert(const Item& entry); void remove(const Item& target); void operator +=(const Bag& addend); void operator =(const Bag& source); // CONSTANT functions size_t size( ) const { return many_nodes; } size_t occurrences(const Item& target) const; Item grab( ) const; private: Node *head_ptr; // Head pointer for the list of items size_t many_nodes; // Number of nodes on the list }; //End of Class Bag // NONMEMBER functions for the Bag Bag operator +(const Bag& b1, const Bag& b2); #endif
Background image of page 4
UAH CPE 212 Bag 3 2 // FILE: bag3.cxx // CLASS implemented: Bag (see bag3.h for documentation) // INVARIANT for the Bag ADT: // 1. The items in the Bag are stored on a linked list; // 2. The head pointer of the list is stored in the member variable head_ptr; // 3. The total number of items in the list is stored in the member variable // many_nodes. #include <assert.h> // Provides assert
Background image of page 5

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

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

Page1 / 17

Linked Lists b - UAH CPE 212 Fundamentals of Software...

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