javascript adt - list
TRANSCRIPT
![Page 1: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/1.jpg)
ListA List ADT
![Page 2: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/2.jpg)
List
• Lists are one of the most common
organizing tools people use in their day-to-day lives.
![Page 3: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/3.jpg)
List
• We have :• to-do lists,
• grocery lists,• top-ten lists,
• bottom-ten lists,• and many other types.
![Page 4: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/4.jpg)
List
• Our computer programs can also use lists, particularly if we only have a few items to store in list form.
![Page 5: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/5.jpg)
List
• Lists are especially useful if we don’t have to perform searches on the items in the list or put them into some type of sorted order.
![Page 6: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/6.jpg)
List
• When we need to perform long searches or complex sorts, lists become
less useful, especially with more complex data structures.
![Page 7: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/7.jpg)
A List ADT
• In order to design an ADT for a list, we have to provide a definition of the list, including its properties, as well as the
operations performed on it and by it.
![Page 8: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/8.jpg)
A List ADT
• A list is an ordered sequence of data. Each data item stored in a list is called an element.
• In JavaScript, the elements of a list can be of any data type.
![Page 9: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/9.jpg)
A List ADT
• There is no predetermined number of elements that can be stored in a list.
• The Limit will be the amount of memory available to the program using the list.
![Page 10: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/10.jpg)
A List ADT
• A list with no elements is an empty list.
• The number of elements stored in a
list is called the length of the list.
![Page 11: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/11.jpg)
A List ADT
• You can append an element to the end of a list.
• or you can insert an element into a list after an existing element
• or at the beginning of a list.
![Page 12: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/12.jpg)
A List ADT
• Elements are deleted from a list using a remove operation.
• You can also clear a list so that all of its current elements are removed.
![Page 13: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/13.jpg)
A List ADT
• The elements of a list are displayed using either a toString() operation.
![Page 14: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/14.jpg)
A List ADT
• with a getElement() operation, which displays the value of the current element at a position.
![Page 15: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/15.jpg)
A List ADT
• Lists have properties to describe location. There is the front of a list and the end of a list.
![Page 16: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/16.jpg)
A List ADT
• You can move from one element of a list to the next element using the next() operation.
• you can move backward through a list using
the prev() operation
![Page 17: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/17.jpg)
A List ADT
• You can also move to a numbered position in a list using the moveTo(n) operation.
• where n specifies the position to move to.
![Page 18: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/18.jpg)
A List ADT
• The List ADT does not specify a storage function for a list, but for our implementation will use an array named dataStore.
![Page 19: Javascript ADT - List](https://reader035.vdocument.in/reader035/viewer/2022062308/55c0bcb0bb61eb63448b46fa/html5/thumbnails/19.jpg)
A List ADT