Successfully reported this slideshow.
Upcoming SlideShare
×

# Data Structure: List as abstract data type

985 views

Published on

In this video we will create a simple abstract data type, list. We will define its properties and operations that can be performed on a list. We will not implement list in an programming language in this video. That we will see in upcoming videos of Data Structure using C.

After defining the properties of the list Dr. Yogendra Pal listed some operations like PRINTLIST, END, FIRST, NEXT, PREVIOUS, INSERT, LOCATE, RETRIEVE, DELETE and MAKENULL. We will implement these operations using c programming in upcoming videos.

Complete Data Structure videos can be found here: https://goo.gl/HX72pI
Join Data Structure using C online course: https://goo.gl/I1ZHK3

Learn By Watch is a YouTube channel where we teach various subjects in Hindi. You can watch and subscribe our YouTube channel from here: https://goo.gl/JT9uzi

Published in: Engineering
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### Data Structure: List as abstract data type

1. 1. Abstract Data Types: Lists
2. 2. List • A List is a sequence of zero or more elements. a1, a2, a3, a4, ………..,an Where n  0, a1 is the first element an is the last element n is length of the list if n = 0, the list is empty (no element) Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 2
3. 3. More about lists • Elements are linearly ordered. ai precedes ai+1 for i = 1, 2, 3,… (n-1) ai follows ai-1 for i = 2, 3,… n • Element ai is at position i a1, a2, a3, a4, ………..,an Not a list a1, a3, a5, a7, ………..,an Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 3 1 2 3 4 n Position of element.
4. 4. More about lists a1, a2, a3, a4, a5 a1, a2, a3, a4, a5, a6, a7 a1, a2, a3, a4 a1, a2, a3 Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 4
5. 5. LIST: Abstract Data Type • L: List of elements • e: an element • p: position LIST ADT Properties - Sequence of linearly ordered elements. Operations • Insert(e, p, L) • Locate(e,L) • Retrieve(p,L) • Delete(p,L) • Next(p,L) • Previous(p,L) • MakeNull(L) • First(L) • PrintList(L) • END(L) Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 5
6. 6. Print all elements of the LIST ADT • PRINTLIST(L) • Print the elements of L in order of occurrence. Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 6
7. 7. End of list a1, a2, a3, a4 ,…………, an • END(L) • Returns the position following an on the list. a1, a2, a3, a4, a5, a6, a7 • END(L) will return 8 for this list Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 7 1 2 3 4 7 Position of element.
8. 8. First position on LIST ADT a1, a2, a3, a4 ,…………, an • FIRST(L) • Returns the first position on the list. • If L is empty the position returned is END(L) Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 8 1 2 3 4 n Position of element.
9. 9. Next and Previous position on LIST ADT • NEXT(p, L) • Returns the position following the position p on the list. • PREVIOUS(p, L) • Returns the position preceding the position p on the list. • If p is the last position on the list then NEXT(p,L) will return END(L). • PREVIOUS is undefined if p is 1. • Both functions are undefined if L has no position p. Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 9
10. 10. Insert an element in LIST ADT a1, a2, a3, a4, a5, a6, a7 • INSERT(e, p, L) a1, a2, a3, a4 ,……ap ,…… an a1, a2, a3, a4 ,……,ap-1, e, ap ,…… an • INSERT(3, 5, a1, a2, a3, a4, a5, a6, a7) a1, a2, a3, a4, a5, a6, a7 a1, a2, a3, a4, 3, a5, a6, a7 • if p = END(L) then L becomes a1, a2, a3, a4, a5, a6, a7, e Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 10
11. 11. Locate an element in LIST ADT 33, 90, 76, 21, 65, 36, 87 • LOCATE(e, L) • Returns the position of e on list L • LOCATE(76,L) • Return 3 • If e appears more than once, then the position of first occurrence is returned. • If e does not appear than END(L) is returned. Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 11 1 2 3 4 7 Position of element.
12. 12. Retrieve an element from LIST ADT 33, 90, 76, 21, 65, 36, 87 • Retrieve(p, L) • Returns the element at position p from the List. • Retrieve(3, L) will return 76 • The result is undefined if p = END(L) or if L has no position p Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 12 1 2 3 4 7 Position of element.
13. 13. Delete an element from the list a1, a2, a3, a4, a5, a6, a7 • DELETE(p, L) a1, a2, a3, a4 ,……ap ,…… an a1, a2, a3, a4 ,……,ap-1, ap+1 ,…… an • DELETE(5, L) a1, a2, a3, a4, a5, a6, a7 a1, a2, a3, a4, a6, a7 • Result is undefined if L has no position p Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 13
14. 14. Empty entire LIST ADT • MAKENULL(L) • L becomes empty and returns position END(L) Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 14
15. 15. Buy this course • You can buy this course from www.learnbywatch.com/course/data-structure-using-c-online-course https://goo.gl/I1ZHK3 • You can also send an e-mail at info@learnbywatch.com to know more about this course or get discount. Data Structure using C | Dr. Yogendra Pal | www.LearnByWatch.com 15