SlideShare ist ein Scribd-Unternehmen logo
1 von 7
Downloaden Sie, um offline zu lesen
Linked Lists

            An Alternative Collections Data
            Structure




       What Is A Linked List?

          A data structure using memory that
          expands and shrinks as needed
          Relies on identical nodes “pointing” or
          “linked” to other nodes
          Each node is an instance of a class (i.e. an
          object)




     Head




       Example Declarations
public class IntNode
{
  private int data;
  private IntNode link;
  …
}
                          OR
public class Part
{
  private int partNo;
  private double price;
  private Part link;
  …
}
Special Nodes
Head node
  The first node in a linked list
  Almost all programs using linked lists will
  maintain a pointer to the head node
  An empty list is represented by storing Null in the
  head variable
Tail node
  The last node in a linked list
  Many programs maintain a pointer to the tail
  node
  A tail node points to a “null” reference
  In an empty list tail will also be Null




   Necessary Methods

 Methods to access and modify data:
 e.g. getData(), getLink(), setData(int
   newData), setLink(??? newLink)
 Methods for creating nodes
 i.e. constructors
 Methods for adding and removing
 nodes




   Caution!

   Always make sure that your linked list
   methods work correctly with an empty
   list.
Adding a Node to the Front
    of a List
     1. Create a new node with the desired data, and
        the link pointing to the current head node
     2. Make the “head” pointer point to the new node
     What happens if we started with an empty list?




remove

   Head




     Removing the First Node
     of a List
        Make the head pointer point to what the
        current head node is pointing to
     What happens to the original head node?
     What if there was only one node in the list?



remove

   Head




    Adding a Node After a
    Selected Node
     1. Create a new node pointing to whatever the
        selected node is currently pointing to
     2. Make the selected node point to the new node
     What happens if the selected node was the last node
        in the list?


                                 remove



 Head           Selected
Removing a Selected Node



      Head


                       Selected
                  Can we remove this?




     Removing the Node After
        a Selected Node

     Head
              Selected
                          Can we remove this?
Desired Result:




      Head
              Selected

What happens if we removed the tail node?




       Manipulating Entire Linked
       Lists
         Traverse the entire list in a loop that
         terminates when the null pointer is
         reached
         In the body of the loop perform the
         necessary operation(s)
Manipulating Entire Linked
       Lists
           Examples:
               count the elements of the list
               Print the elements of the list
               Update the values in the list (e.g. increase
               all prices by 10%)
           If implemented in the same class as the
           node (i.e. no separate list class), it is better
           to use static methods, this way the method
           can be used for empty lists




       Sample Code
IntNode current;
for (current = head; current != null; current = current.link)
{
    …
}
                            Or:
IntNode current;
current = head;
while (current != null)
{
    …
    current = current.link;
}




       Copying an Entire List

public static IntNode copyList (IntNode head)
{
   if (head == null) return null;
   IntNode copyHead = new IntNode (head.data,null);
   IntNode copyTail = copyHead;
   IntNode source = head;
   while (source.link != null)
   {
          source = source.link;
          copyTail.addNodeAfter(source.data);
          copyTail = copyTail.link;
   }
   return copyHead;
}
Copying a Part of a List

      Given a start node and an end node
      make a copy of that part of the list
      Can we return both the head and tail
      of the copy?
      How does the method work? Is it that
      much different from copying the full
      list?




  Linked List Application –
  IntLinkedBag

      Keeps track of integer elements
      Can add or delete elements
      Answers questions about its elements
      Can add all the contents of another
      bag
      Grows and shrinks in size as needed




   IntLinkedBag - Methods
public void add (int element)
public void addAll (IntLinkedBag addend)
public int countOccurences(int target)
public boolean remove (int target)
public int size()
public void trimToSize()
public static IntLinkedBag union (IntLinkedBag b1,
                                       IntLinkedBag b2)
public int grab()
public void ensureCapacity (int minimumCapacity) ???
public int getCapacity() ???
Another Linked List Application
 - DoubleLinkedSeq
Similar to bag but sequence is preserved
An additional instance variable is needed to hold
the position of the “current” element
Two additional instance variables “tail” and
“precursor” may be used for convenience
Some methods can be preserved, others must be
modified
Additional methods are needed
Implementation: assignment 5




  Doubly Linked Lists

     Similar to linked lists with pointers in
     both directions

Head                                          Tail




 Array vs. Linked Lists vs.
 Doubly Linked Lists
  Which is better for the following
  operations?:
       Random access
       Frequent additions/removals in the
       middle of a sequence
       Frequent forward and backward
       searching of a sequence
       Frequent size changes

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Chapter 14
Chapter 14Chapter 14
Chapter 14
 
linked_lists
linked_listslinked_lists
linked_lists
 
ArrayList in JAVA
ArrayList in JAVAArrayList in JAVA
ArrayList in JAVA
 
Data structure
Data structureData structure
Data structure
 
Ap Power Point Chpt9
Ap Power Point Chpt9Ap Power Point Chpt9
Ap Power Point Chpt9
 
LPR - Week 1
LPR - Week 1LPR - Week 1
LPR - Week 1
 
Python set
Python setPython set
Python set
 
computer notes - List implementation
computer notes - List implementationcomputer notes - List implementation
computer notes - List implementation
 
Generics Collections
Generics CollectionsGenerics Collections
Generics Collections
 
Python Dictionary.pptx
Python Dictionary.pptxPython Dictionary.pptx
Python Dictionary.pptx
 
linked_lists4
linked_lists4linked_lists4
linked_lists4
 
Lists
Lists Lists
Lists
 
Beautiful Research Data (Structured Data and Open Refine)
Beautiful Research Data (Structured Data and Open Refine)Beautiful Research Data (Structured Data and Open Refine)
Beautiful Research Data (Structured Data and Open Refine)
 
Pa1 session 2
Pa1 session 2 Pa1 session 2
Pa1 session 2
 
Linked lists
Linked listsLinked lists
Linked lists
 
The awesome algorithm
The awesome algorithmThe awesome algorithm
The awesome algorithm
 
List view1
List view1List view1
List view1
 
LectureNotes-03-DSA
LectureNotes-03-DSALectureNotes-03-DSA
LectureNotes-03-DSA
 
3 searching algorithms in Java
3 searching algorithms in Java3 searching algorithms in Java
3 searching algorithms in Java
 
linked_lists3
linked_lists3linked_lists3
linked_lists3
 

Andere mochten auch

Nawawalang Paraiso
Nawawalang ParaisoNawawalang Paraiso
Nawawalang Paraisoyencara
 
Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»RussianServiceBook
 
Light Emitting Diode
Light Emitting DiodeLight Emitting Diode
Light Emitting Diodesalman01
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)salman01
 
Глава 7. История развития компании «КОМСТАР-ОТС»
Глава 7.  История развития компании «КОМСТАР-ОТС»Глава 7.  История развития компании «КОМСТАР-ОТС»
Глава 7. История развития компании «КОМСТАР-ОТС»RussianServiceBook
 
Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»RussianServiceBook
 
7th Grade Gifted Language Arts
7th Grade Gifted Language Arts7th Grade Gifted Language Arts
7th Grade Gifted Language ArtsDebbie Harper
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)salman01
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)salman01
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)salman01
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)salman01
 
Глава 1. Революция услуг в мировой экономике
 Глава 1. Революция услуг в мировой экономике  Глава 1. Революция услуг в мировой экономике
Глава 1. Революция услуг в мировой экономике RussianServiceBook
 
Глава 6. История развития компании «МегаФон» [обновление - март 2012]
Глава 6.  История развития компании «МегаФон» [обновление - март 2012]Глава 6.  История развития компании «МегаФон» [обновление - март 2012]
Глава 6. История развития компании «МегаФон» [обновление - март 2012]RussianServiceBook
 
Глава 6. История развития компании «МегаФон»
Глава 6.  История развития компании «МегаФон»Глава 6.  История развития компании «МегаФон»
Глава 6. История развития компании «МегаФон»RussianServiceBook
 
Light Emitting Diode
Light Emitting DiodeLight Emitting Diode
Light Emitting Diodesalman01
 
light emmitting diode
light emmitting diodelight emmitting diode
light emmitting diodesalman01
 

Andere mochten auch (18)

Nawawalang Paraiso
Nawawalang ParaisoNawawalang Paraiso
Nawawalang Paraiso
 
Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»
 
Light Emitting Diode
Light Emitting DiodeLight Emitting Diode
Light Emitting Diode
 
Img025
Img025Img025
Img025
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)
 
Глава 7. История развития компании «КОМСТАР-ОТС»
Глава 7.  История развития компании «КОМСТАР-ОТС»Глава 7.  История развития компании «КОМСТАР-ОТС»
Глава 7. История развития компании «КОМСТАР-ОТС»
 
Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»Глава 9. История развития компании «Евросеть»
Глава 9. История развития компании «Евросеть»
 
7th Grade Gifted Language Arts
7th Grade Gifted Language Arts7th Grade Gifted Language Arts
7th Grade Gifted Language Arts
 
Ianbresume
IanbresumeIanbresume
Ianbresume
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)
 
Light Emitting Diode9(LED)
Light Emitting Diode9(LED)Light Emitting Diode9(LED)
Light Emitting Diode9(LED)
 
Глава 1. Революция услуг в мировой экономике
 Глава 1. Революция услуг в мировой экономике  Глава 1. Революция услуг в мировой экономике
Глава 1. Революция услуг в мировой экономике
 
Глава 6. История развития компании «МегаФон» [обновление - март 2012]
Глава 6.  История развития компании «МегаФон» [обновление - март 2012]Глава 6.  История развития компании «МегаФон» [обновление - март 2012]
Глава 6. История развития компании «МегаФон» [обновление - март 2012]
 
Глава 6. История развития компании «МегаФон»
Глава 6.  История развития компании «МегаФон»Глава 6.  История развития компании «МегаФон»
Глава 6. История развития компании «МегаФон»
 
Light Emitting Diode
Light Emitting DiodeLight Emitting Diode
Light Emitting Diode
 
light emmitting diode
light emmitting diodelight emmitting diode
light emmitting diode
 

Ähnlich wie linklisr

Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structuresNiraj Agarwal
 
List Data Structure
List Data StructureList Data Structure
List Data StructureZidny Nafan
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5Teksify
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structuresGlobalidiots
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfadvancethchnologies
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfgiriraj65
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptxssuserd2f031
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfadityacomputers001
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfaliracreations
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdffms12345
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfalicesilverblr
 
LinkedList Presentation.pptx
LinkedList Presentation.pptxLinkedList Presentation.pptx
LinkedList Presentation.pptxwahid431192
 

Ähnlich wie linklisr (20)

Fundamentals of data structures
Fundamentals of data structuresFundamentals of data structures
Fundamentals of data structures
 
Linked lists
Linked listsLinked lists
Linked lists
 
Linked list
Linked list Linked list
Linked list
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
List Data Structure
List Data StructureList Data Structure
List Data Structure
 
csc211_lecture_21.pptx
csc211_lecture_21.pptxcsc211_lecture_21.pptx
csc211_lecture_21.pptx
 
Data structure
 Data structure Data structure
Data structure
 
Data Structure Lecture 5
Data Structure Lecture 5Data Structure Lecture 5
Data Structure Lecture 5
 
Funddamentals of data structures
Funddamentals of data structuresFunddamentals of data structures
Funddamentals of data structures
 
3.ppt
3.ppt3.ppt
3.ppt
 
3.ppt
3.ppt3.ppt
3.ppt
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
 
Objective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdfObjective The purpose of this exercise is to create a Linke.pdf
Objective The purpose of this exercise is to create a Linke.pdf
 
Linked List
Linked ListLinked List
Linked List
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
 
Linked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdfLinked List Objective The purpose of this exercise is to cr.pdf
Linked List Objective The purpose of this exercise is to cr.pdf
 
Objective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdfObjective The purpose of this exercise is to create a Linked List d.pdf
Objective The purpose of this exercise is to create a Linked List d.pdf
 
In this lab we will write code for working with a Linked List. Node .pdf
In this lab we will write code for working with a Linked List.  Node .pdfIn this lab we will write code for working with a Linked List.  Node .pdf
In this lab we will write code for working with a Linked List. Node .pdf
 
Please and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdfPlease and Thank youObjective The purpose of this exercise is to .pdf
Please and Thank youObjective The purpose of this exercise is to .pdf
 
LinkedList Presentation.pptx
LinkedList Presentation.pptxLinkedList Presentation.pptx
LinkedList Presentation.pptx
 

Kürzlich hochgeladen

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxAshokKarra1
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsManeerUddin
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...JojoEDelaCruz
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationRosabel UA
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptshraddhaparab530
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 

Kürzlich hochgeladen (20)

Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptxYOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
YOUVE_GOT_EMAIL_PRELIMS_EL_DORADO_2024.pptx
 
Karra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptxKarra SKD Conference Presentation Revised.pptx
Karra SKD Conference Presentation Revised.pptx
 
Food processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture honsFood processing presentation for bsc agriculture hons
Food processing presentation for bsc agriculture hons
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
ENG 5 Q4 WEEk 1 DAY 1 Restate sentences heard in one’s own words. Use appropr...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Activity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translationActivity 2-unit 2-update 2024. English translation
Activity 2-unit 2-update 2024. English translation
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
Integumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.pptIntegumentary System SMP B. Pharm Sem I.ppt
Integumentary System SMP B. Pharm Sem I.ppt
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 

linklisr

  • 1. Linked Lists An Alternative Collections Data Structure What Is A Linked List? A data structure using memory that expands and shrinks as needed Relies on identical nodes “pointing” or “linked” to other nodes Each node is an instance of a class (i.e. an object) Head Example Declarations public class IntNode { private int data; private IntNode link; … } OR public class Part { private int partNo; private double price; private Part link; … }
  • 2. Special Nodes Head node The first node in a linked list Almost all programs using linked lists will maintain a pointer to the head node An empty list is represented by storing Null in the head variable Tail node The last node in a linked list Many programs maintain a pointer to the tail node A tail node points to a “null” reference In an empty list tail will also be Null Necessary Methods Methods to access and modify data: e.g. getData(), getLink(), setData(int newData), setLink(??? newLink) Methods for creating nodes i.e. constructors Methods for adding and removing nodes Caution! Always make sure that your linked list methods work correctly with an empty list.
  • 3. Adding a Node to the Front of a List 1. Create a new node with the desired data, and the link pointing to the current head node 2. Make the “head” pointer point to the new node What happens if we started with an empty list? remove Head Removing the First Node of a List Make the head pointer point to what the current head node is pointing to What happens to the original head node? What if there was only one node in the list? remove Head Adding a Node After a Selected Node 1. Create a new node pointing to whatever the selected node is currently pointing to 2. Make the selected node point to the new node What happens if the selected node was the last node in the list? remove Head Selected
  • 4. Removing a Selected Node Head Selected Can we remove this? Removing the Node After a Selected Node Head Selected Can we remove this? Desired Result: Head Selected What happens if we removed the tail node? Manipulating Entire Linked Lists Traverse the entire list in a loop that terminates when the null pointer is reached In the body of the loop perform the necessary operation(s)
  • 5. Manipulating Entire Linked Lists Examples: count the elements of the list Print the elements of the list Update the values in the list (e.g. increase all prices by 10%) If implemented in the same class as the node (i.e. no separate list class), it is better to use static methods, this way the method can be used for empty lists Sample Code IntNode current; for (current = head; current != null; current = current.link) { … } Or: IntNode current; current = head; while (current != null) { … current = current.link; } Copying an Entire List public static IntNode copyList (IntNode head) { if (head == null) return null; IntNode copyHead = new IntNode (head.data,null); IntNode copyTail = copyHead; IntNode source = head; while (source.link != null) { source = source.link; copyTail.addNodeAfter(source.data); copyTail = copyTail.link; } return copyHead; }
  • 6. Copying a Part of a List Given a start node and an end node make a copy of that part of the list Can we return both the head and tail of the copy? How does the method work? Is it that much different from copying the full list? Linked List Application – IntLinkedBag Keeps track of integer elements Can add or delete elements Answers questions about its elements Can add all the contents of another bag Grows and shrinks in size as needed IntLinkedBag - Methods public void add (int element) public void addAll (IntLinkedBag addend) public int countOccurences(int target) public boolean remove (int target) public int size() public void trimToSize() public static IntLinkedBag union (IntLinkedBag b1, IntLinkedBag b2) public int grab() public void ensureCapacity (int minimumCapacity) ??? public int getCapacity() ???
  • 7. Another Linked List Application - DoubleLinkedSeq Similar to bag but sequence is preserved An additional instance variable is needed to hold the position of the “current” element Two additional instance variables “tail” and “precursor” may be used for convenience Some methods can be preserved, others must be modified Additional methods are needed Implementation: assignment 5 Doubly Linked Lists Similar to linked lists with pointers in both directions Head Tail Array vs. Linked Lists vs. Doubly Linked Lists Which is better for the following operations?: Random access Frequent additions/removals in the middle of a sequence Frequent forward and backward searching of a sequence Frequent size changes