CSE1301 Computer Programming: Lecture 33 Linked Lists.

Slides:



Advertisements
Similar presentations
C and Data Structures Baojian Hua
Advertisements

1 CSE1301 Computer Programming: Lecture 27 List Manipulation.
FIFO Queues CSE 2320 – Algorithms and Data Structures Vassilis Athitsos University of Texas at Arlington 1.
CS 11 C track: lecture 7 Last week: structs, typedef, linked lists This week: hash tables more on the C preprocessor extern const.
SEG4110 – Advanced Software Design and Reengineering TOPIC J C++ Standard Template Library.
EC-111 Algorithms & Computing Lecture #7 Instructor: Jahan Zeb Department of Computer Engineering (DCE) College of E&ME NUST.
EC-211 DATA STRUCTURES LECTURE 2. EXISTING DATA STRUCTURES IN C/C++ ARRAYS – A 1-D array is a finite, ordered set of homogeneous elements – E.g. int a[100]
Introduction to Linked Lists In your previous programming course, you saw how data is organized and processed sequentially using an array. You probably.
Structs CSE 2451 Rong Shi. Structures Structure – one or more values, called members, with possibly dissimilar types that are stored together – Group.
M180: Data Structures & Algorithms in Java
Searching “It is better to search, than to be searched” --anonymous.
CS 206 Introduction to Computer Science II 10 / 22 / 2008 Instructor: Michael Eckmann.
Lecture 3 Feb 4 summary of last week’s topics and review questions (handout) Today’s goals: Chapter 1 overview (sections 1.4 to 1.6) c++ classes constructors,
Introduction to C Programming CE Lecture 11 Sorting and Searching using Arrays.
CS 206 Introduction to Computer Science II 11 / 04 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 10 / 20 / 2008 Instructor: Michael Eckmann.
1 Lecture Today’s topic Arrays Reading for this Lecture: –Chaper 11.
© The McGraw-Hill Companies, 2006 Chapter 5 Arrays.
CS 206 Introduction to Computer Science II 03 / 16 / 2009 Instructor: Michael Eckmann.
CS 206 Introduction to Computer Science II 11 / 12 / 2008 Instructor: Michael Eckmann.
1 CSE1301 Computer Programming: Lecture 30 Linked Lists (Part 2)
CSE1301 Computer Programming: Lecture 32 List Sorting.
Summary of lectures (1 to 11)
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 12: Arrays.
Introduction to C Programming CE Lecture 19 Linear Linked Lists.
CSE1301 Computer Programming: Revision. Topics Type of questions What do you need to know? About the exam Exam technique Sample questions.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
(c) University of Washingtonhashing-1 CSC 143 Java Hashing Set Implementation via Hashing.
Design and Analysis of Algorithms CSC201 Shahid Hussain 1.
CSE 131 Computer Science 1 Module 9: Linked Lists Using references to link objects Basic operations on linked lists Implementing a linked list of integers.
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.
1 Chapter 13 Recursion. 2 Chapter 13 Topics l Meaning of Recursion l Base Case and General Case in Recursive Function Definitions l Writing Recursive.
INTRODUCTION TO BINARY TREES P SORTING  Review of Linear Search: –again, begin with first element and search through list until finding element,
CSE1301 Computer Programming: Lecture 26 List Processing (Search)
1 Data Structures CSCI 132, Spring 2014 Lecture 10 Dynamic Memory and Pointers.
What have we learned?. What is a database? An organized collection of related data.
Data Structures and Algorithms TREE. Searching Sequential Searches Time is proportional to n We call this time complexity O(n) Pronounce this “big oh”
Collections behaviour and implementation of collections of primitives and objects.
EASTERN MEDITERRANEAN UNIVERSITY Stacks EENG212 –Algorithms and Data Structures.
CS201: Data Structures and Discrete Mathematics I Hash Table.
Introduction to Programming Lecture 11. ARRAYS They are special kind of data type They are special kind of data type They are like data structures in.
Chapter 13: Structures. In this chapter you will learn about: – Single structures – Arrays of structures – Structures as function arguments – Linked lists.
Elementary Data Organization. Outline  Data, Entity and Information  Primitive data types  Non primitive data Types  Data structure  Definition 
CSE 232: C++ memory management Overview of Arrays Arrays are the simplest kind of data structure –One item right after another in memory (“contiguous range”
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.
Programming Abstractions Cynthia Lee CS106X. Topics:  Priority Queue › Linked List implementation › Heap data structure implementation  TODAY’S TOPICS.
1 Recursion. 2 Chapter 15 Topics  Meaning of Recursion  Base Case and General Case in Recursive Function Definitions  Writing Recursive Functions with.
1 Chapter 13-2 Applied Arrays: Lists and Strings Dale/Weems.
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Array Lists Array Lists Dale.
1.1 Data Structure and Algorithm Lecture 1 Array Record Sequential Search Binary Search Bubble Sort Recursion Complexity Topics.
Higher Computing Science 2016 Prelim Revision. Topics to revise Computational Constructs parameter passing (value and reference, formal and actual) sub-programs/routines,
Dale Roberts Department of Computer and Information Science, School of Science, IUPUI CSCI 240 Elementary Data Structures Linked Lists Linked Lists Dale.
Circular linked list A circular linked list is a linear linked list accept that last element points to the first element.
Stack Data Structure By Marwa M. A. Elfattah. Stack - What A stack is one of the most important non- primitive linear data structure in computer science.
By Anand George SourceLens.org Copyright. All rights reserved. Content Owner - Meera R (meera at sourcelens.org)
Chapter 3: Sorting and Searching Algorithms 3.1 Searching Algorithms.
Data Structure & Algorithms
114 3/30/98 CSE 143 Collection ADTs [Chapter 4] /30/98 Collection ADTs  Many standard ADTs are for collections  Data structures that manage groups.
1 CSE1301 Computer Programming: Where are we now in the CSE1301 syllabus?
CPSC 252 Linked Lists III Page 1 Variations on Singly Linked Lists Inserting or deleting at the front of a list is different from at any other point in.
ECE Application Programming
Linked Lists Chapter 6 Section 6.4 – 6.6
Efficiency of in Binary Trees
Programming Abstractions
Introduction to Linked Lists
Chapter 16-2 Linked Structures
Searching CSCE 121 J. Michael Moore.
ArrayLists.
Data Structures & Algorithms
FIFO Queues CSE 2320 – Algorithms and Data Structures Alexandra Stefan
Presentation transcript:

CSE1301 Computer Programming: Lecture 33 Linked Lists

Topics Linked list List element Searching a linked list

Recall: Sorted List 01234

01234 Ann

Recall: Sorted List Ann

Recall: Sorted List Ann Dave

Recall: Sorted List Ann Dave

Recall: Sorted List Ann Dave Humphry

Recall: Sorted List Ann Dave Humphry

Recall: Sorted List Ann Dave Humphry Ben

Recall: Sorted List Ann Dave Humphry Ben

Recall: Sorted List Ann Dave Humphry Ben

Recall: Sorted List Ann Dave Humphry Ben

Recall: Sorted List Ann Dave Humphry Ben Q: Is there an alternative way to implement a sorted list? A: Linked List

01234 Ann Dave Humphry Ben First

01234 Ann Dave Humphry Ben First

01234 Ann Dave Humphry Ben First

01234 Ann Dave Humphry Ben First

01234 Ann Dave Humphry First Ben

01234 Ann Dave Humphry Ben First

01234 Ann Dave Humphry Ben First

01234 Ann Dave Humphry Ben First Amy

01234 Ann Dave Humphry Ben First Amy

01234 Ann Dave Humphry Ben First Amy

01234 Ann Dave Humphry Ben First Amy

01234 first element index of next element item invalid index (eg. -1)

Linked List Uses an array to form a sorted list Each element has a link to the next item first

List Element struct ListElementRec { int item; int next; }; typedef struct ListElementRec ListElement; 2 item next 5

What will a program have? An array of these structs ListElement list[maxListLength]; A variable to store the position of the first element of the list int first; The last element in the list must contain a non valid integer in its next field const int END = -1;

Accessing list items First element (a struct) list[first]; First item in list list[first].item; Index of next element list[first].next;

Accessing list items Next item in list int index; list[list[index].next].item; index first END

Searching in a linked list See Algorithm in Lecture Notes Example: Trace values for: index linkedList[index].item linkedList[index].next

Summary In a linked list, list elements don't have to be ordered in the array itself. A second field in the list element structure, "next", maintains the list ordering. Next lecture: adding and deleting from a linked list