APS105 Lists. Structures Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct.

Slides:



Advertisements
Similar presentations
Linked Lists Mohammed Almashat CS /03/2006.
Advertisements

Linked Lists CS-212 Dick Steflik. Linked Lists A sequential collection of information Can be unordered; i.e. in no specific order Can be ordered; may.
Linked Lists.
DATA STRUCTURES USING C++ Chapter 5
LIST PROCESSING.
Data Structure Lecture-5
Data Structure Lecture-3 Prepared by: Shipra Shukla Assistant Professor Kaziranga University.
M180: Data Structures & Algorithms in Java
Data Structures: A Pseudocode Approach with C
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Linked Lists in C and C++ By Ravi Prakash PGT(CS).
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are crated using the class definition. Programming techniques.
Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Sixth Edition Chapter 17: Linked Lists.
C++ Programming: Program Design Including Data Structures, Third Edition Chapter 17: Linked Lists.
COMP103 - Linked Lists (Part A)1 Chapter 17 Truly dynamic memory management.
Chapter 12 C Data Structures Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
Starting Out with C++: Early Objects 5/e © 2006 Pearson Education. All Rights Reserved Starting Out with C++: Early Objects 5 th Edition Chapter 17 Linked.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 12 – Data Structures Outline 12.1Introduction.
1 Stack Data : a collection of homogeneous elements arranged in a sequence. Only the first element may be accessed Main Operations: Push : insert an element.
Data Structures Using C++ 2E
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
1 Chapter 16-1 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion.
Chapter 5 – Dynamic Data Structure Par1: Abstract Data Type DATA STRUCTURES & ALGORITHMS Teacher: Nguyen Do Thai Nguyen
Lists 1. Introduction Data: A finite sequence of data items. Operations: Construction: Create an empty list Empty: Check if list is empty Insert: Add.
ABSTRACT DATA TYPES Data types, data structures, abstract data types, Java/C++ classes, C++ structs.
Chapter 1 Object Oriented Programming. OOP revolves around the concept of an objects. Objects are created using the class definition. Programming techniques.
Lists, Stacks and Queues in C Yang Zhengwei CSCI2100B Data Structures Tutorial 4.
1 Chapter 16 Linked Structures Dale/Weems. 2 Chapter 16 Topics l Meaning of a Linked List l Meaning of a Dynamic Linked List l Traversal, Insertion and.
1 Chapter 16 Linked Structures Dale/Weems/Headington.
Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy Walters, and Godfrey Muganda Chapter 17: Linked Lists.
The List ADT A sequence of zero or more elements A 1, A 2, A 3, … A N-1 N: length of the list A 1 : first element A N-1 : last element A i : position i.
Linked Lists Objects->Connected->by->Pointers. What is a Linked List? List: a collection Linked: any individual item points to another item to connect.
Generic lists Vassilis Athitsos. Problems With Textbook Interface? Suppose that we fix the first problem, and we can have multiple stacks. Can we have.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
Data Structures. Abstract Data Type A collection of related data is known as an abstract data type (ADT) Data Structure = ADT + Collection of functions.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Chapter 17: Linked Lists. Objectives In this chapter, you will: – Learn about linked lists – Learn the basic properties of linked lists – Explore insertion.
Linked list: a list of items (nodes), in which the order of the nodes is determined by the address, called the link, stored in each node C++ Programming:
1 Midterm 1 on Friday February 12 Closed book, closed notes No computer can be used 50 minutes 4 questions Write a function Write program fragment Explain.
Data Structure & Algorithms
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Copyright © 2011 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Seventh Edition by Tony Gaddis, Judy.
Copyright © 2014, 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with C++ Early Objects Eighth Edition by Tony Gaddis,
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 17: Linked Lists.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 18: Linked Lists.
UNIT-V ABSTRACT DATA TYPE 1.LIST 2.STACK 3.QUEUE EC6301-II-ECE-C.
Chapter 16: Linked Lists.
Programming Circular Linked List.
C++ Programming:. Program Design Including
Chapter 12 – Data Structures
Linked List :: Basic Concepts
CSCI-255 LinkedList.
UNIT – I Linked Lists.
Linked Lists Chapter 6 Section 6.4 – 6.6
UNIT-3 LINKED LIST.
Data Structures and Algorithms
Linked lists.
Lists.
Lists.
Chapter 16-2 Linked Structures
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Linked List Intro CSCE 121 J. Michael Moore.
11-3 LINKED LISTS A linked list is a collection of data in which each element contains the location of the next element—that is, each element contains.
Data Structures and Algorithms
Chapter 16 Linked Structures
General List.
Linked List Intro CSCE 121.
Linked lists.
Abstract Data Types Stacks CSCI 240
Linked Lists.
Presentation transcript:

APS105 Lists

Structures

Arrays allow a collection of elements –All of the same type How to collect elements of different types? –Structures; in C: struct General form: struct { } ;

Example A struct of stock items at a store:.

Separate Definition from Declaration.

Using Typedef Can define your own types using typedef ! General form: typedef ; Examples:.

Doing typedef and definition at once:.

Referencing Struct Members.

Structs and Pointers StockItem x; StockItem *p; p = &x; // p points to x // ways to set quantity to 500:.

Malloc a Struct (StockItem).

Lists

Intro A list is a sequence of items –can implement lists different ways: a group of variables an array using pointers (as we will see) Typical list operations –start a new, empty list –insert a new element into the list –find an item with a certain value in the list –delete an item from the list –print the list Abstract Data Type (ADT) –A list is an example of an ADT –An ADT is a concept –there are multiple ways to implement an ADT

The Problem with Arrays Insert an item into the middle of the list: Delete an item from the middle of the list: What if the array isn’t big enough? X

Flexible List: “Linked List” Insert an item into the middle of the list: Delete an item from the middle of the list: X

Implementing a Linked List of int s.

Allocating a new Node a function to allocate & initialize a node.

Creating a List: Adding to the end.

Creating a List: Adding to the front.

Function to Print a List.

Deleting the First Node of a List info: 5 link: myList info: 3 link: info: 1 link:

Function to Delete first Node.

Delete first Node: return new head.

Function to return true if an item found.

Function to Delete Entire List.

Function to Add Element to End of List.

Deleting the Last Node of a List info: 5 link: myList info: 3 link: info: 1 link:

Function to Delete Last Element.

Inserting into an Ordered List info: 1 link: myList info: 3 link: info: 5 link: 4

Function to Insert into Ordered List.

Using Recursion on Lists

Printing a List using Recursion can think of a list recursively as: a head node plus a list.

Deleting a List using Recursion.

Finding an Item using Recursion.

Compare 2 Lists: true if identical.

Insert into an Ordered List.