UNIT – I Linked Lists.

Slides:



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

Linked Lists.
Linear Lists – Linked List Representation
Chapter 17 Linked List Saurav Karmakar Spring 2007.
M180: Data Structures & Algorithms in Java
Linked Lists Compiled by Dr. Mohammad Alhawarat CHAPTER 04.
Class 3: Linked Lists. cis 335 Fall 2001 Barry Cohen What is a linked list? n A linked list is an ordered series of ‘nodes’ n Each node contains some.
Copyright © 2008 Pearson Addison-Wesley. All rights reserved. Chapter 13 Pointers and Linked Lists.
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.
Self Referential Structure. A structure may not contain a member of its own type. struct check { int item; struct check n; // Invalid };
Department of Computer Science Data Structures Using C++ 2E Chapter 5 Linked Lists.
Week 4 - Monday.  What did we talk about last time?  Queues  Implementing queues with circular arrays.
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.
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.
Review 1 Polish Notation Prefix Infix Postfix Precedence of Operators Converting Infix to Postfix Evaluating Postfix.
2/21/20161 List Operations Advanced Programming Ananda Gunawardena.
 Array is a data structure were elements are stored in consecutive memory location.in the array once the memory is allocated.it cannot be extend any more.
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 Linked List. Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion.
Data Structure & Algorithms
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Linked Lists Outline Introduction Self-Referential Structures.
Single Linked Lists Objectives In this lesson, you will learn to: *Define single linked list *Identify the following types of linked lists: Single linked.
Doubly Linked List Exercises Sometimes it is useful to have a linked list with pointers to both the next and previous nodes. This is called a doubly linked.
Linked Lists Chapter Introduction To The Linked List ADT Linked list: set of data structures (nodes) that contain references to other data structures.
Programming Circular Linked List.
Unit – I Lists.
Cpt S 122 – Data Structures Abstract Data Types
Pointers and Linked Lists
Pointers and Linked Lists
5.13 Recursion Recursive functions Functions that call themselves
CSCI-255 LinkedList.
Lectures linked lists Chapter 6 of textbook
Linked Lists Chapter 6 Section 6.4 – 6.6
Review Deleting an Element from a Linked List Deletion involves:
Data Structure and Algorithms
Lists CS 3358.
Linked Lists.
UNIT-3 LINKED LIST.
ENERGY 211 / CME 211 Lecture 12 October 17, 2008.
Linked lists Motivation: we can make arrays, but their functionality is slightly limited and can be difficult to work with Biggest issue: size management.
Lists.
CSCI 3333 Data Structures Linked Lists.
Sequences 9/18/ :20 PM C201: Linked List.
Tree data structure.
Programmazione I a.a. 2017/2018.
LINKED LISTS CSCD Linked Lists.
Lists.
Object Oriented Programming COP3330 / CGS5409
DATA STRUCTURE QUEUE.
Arrays and Linked Lists
Chapter 18: Linked Lists.
Tree data structure.
Sequences 11/27/2018 1:37 AM Singly Linked Lists Singly Linked Lists.
Linked List Intro CSCE 121 J. Michael Moore.
Pointers and Linked Lists
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.
Lists CSE 373 Data Structures.
Indirection.
Linked Lists Chapter 4.
Chapter 17: Linked Lists.
LINKED LISTS.
Introduction to C++ Linear Linked Lists
Linked Lists.
CS148 Introduction to Programming II
Lecture No.02 Data Structures Dr. Sohail Aslam
Lists CSE 373 Data Structures.
CS148 Introduction to Programming II
Abstract Data Types Stacks CSCI 240
Linked Lists.
CMPT 225 Lecture 5 – linked list.
Presentation transcript:

UNIT – I Linked Lists

Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion

Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion

Introduction Definitions Advantages Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists Advantages

Introduction Definitions Advantages Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists Advantages

Lists and arrays Lists:

Lists and arrays Arrays: Index 1 2 3 Value 44 5 96 {Size of the following array is = 4} Index 1 2 3 Value 44 5 96

Introduction Definitions Advantages Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists Advantages

Nodes and pointers

Introduction Definitions Advantages Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists Advantages

Single linked lists

Introduction Definitions Advantages Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists Advantages

Double Linked Lists

Introduction Definitions Advantages Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists Advantages

Circular Lists

Introduction Definitions Advantages Lists and arrays Nodes and pointers Single Linked Lists Double Linked Lists Circular Lists Advantages

Advantages The Linked List advantages are collected because of the array disadvantages, array disadvantages are: Array Size Memory allocation Insertion and Deletion

Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion

Insertion Description Insertion at the top of the list Insertion at the end of the list Insertion in the middle of the list

Insertion Description Insertion at the top of the list Insertion at the end of the list Insertion in the middle of the list

Insertion at the top Steps: Create a Node Set the node data Values Connect the pointers

Insertion Description 48 17 142 head // Follow the previous steps and we get Step 1 Step 2 Step 3 head 93

Insertion Description Insertion at the top of the list Insertion at the end of the list Insertion in the middle of the list

Insertion at the end Steps: Create a Node Set the node data Values Connect the pointers

Insertion Description 48 17 142 head // Follow the previous steps and we get Step 1 Step 2 Step 3

Insertion Description Insertion at the top of the list Insertion at the end of the list Insertion in the middle of the list

Insertion in the middle Steps: Create a Node Set the node data Values Break pointer connection Re-connect the pointers

Insertion Description Step 1 Step 2 Step 3 Step 4

Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion

Deletion Description Deleting from the top of the list Deleting from the end of the list Deleting from the middle of the list

Deletion Description Deleting from the top of the list Deleting from the end of the list Deleting from the middle of the list

Deleting from the top Steps Break the pointer connection Re-connect the nodes Delete the node

Deletion Description head 6 42 4 17 head 6 42 4 17 head 42 4 17

Deletion Description Deleting from the top of the list Deleting from the end of the list Deleting from the middle of the list

Deleting from the end Steps Break the pointer connection Set previous node pointer to NULL Delete the node

Deletion Description head 6 42 4 17 head 6 42 4 17 head 6 4 17

Deletion Description Deleting from the top of the list Deleting from the end of the list Deleting from the middle of the list

Deleting from the Middle Steps Set previous Node pointer to next node Break Node pointer connection Delete the node

Deletion Description head 42 4 17 head 42 4 17 head 42 4

Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion

Basic Node Implementation The following code is written in C++: Struct Node { int data; //any type of data could be another struct Node *next; //this is an important piece of code “pointer” };

Outline Introduction Insertion Description Deletion Description Basic Node Implementation Conclusion