List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.
-
Upload
marquez-smail -
Category
Documents
-
view
226 -
download
8
Transcript of List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.
![Page 1: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/1.jpg)
Data Structure
ListEka, Erick, Reddy
© Sekolah Tinggi Teknik Surabaya
1
![Page 2: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/2.jpg)
Array» Fixed Size» Initialization: int[] abc = new int[10];
» Accessing by its index int tmp = abc[0];
2
© Sekolah Tinggi Teknik Surabaya
![Page 3: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/3.jpg)
List» Dynamic Size» Initalization List<int> abc = new List<int>();
» Inserting abc.Add(123);
» Accessing by its index int tmp = abc[0];
3
© Sekolah Tinggi Teknik Surabaya
![Page 4: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/4.jpg)
Array Vs List (1)
4
© Sekolah Tinggi Teknik Surabaya
» Size˃ ArrayFixed Size, but you can use Array.Resize˃ ListDynamic Size
![Page 5: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/5.jpg)
Array Vs List (2)» Dimension˃ Array : Support multi dimensionExample :
˃ List : One DimensionBut we can make it multi too
5
© Sekolah Tinggi Teknik Surabaya
![Page 6: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/6.jpg)
Array Vs List (3)» Function Built In» Like Sort, Reverse, IndexOf, Find, etc˃ ArrayUse System.Array function˃ ListUse its own function
6
© Sekolah Tinggi Teknik Surabaya
![Page 7: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/7.jpg)
Performance Test» Prepare the object to test
» Performance test in inserting, updating, and select 1.000.000 element.
» Using Stopwatch class from System.Diagnostics.
7
© Sekolah Tinggi Teknik Surabaya
![Page 8: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/8.jpg)
Insert 1.000.000 Element
8
© Sekolah Tinggi Teknik Surabaya
» List is slower than Array when inserting, because List resize its length first
![Page 9: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/9.jpg)
Inserting Script
9
© Sekolah Tinggi Teknik Surabaya
![Page 10: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/10.jpg)
Update 1.000.000 Element
10
© Sekolah Tinggi Teknik Surabaya
» When updating its element, list is much faster than array.
![Page 11: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/11.jpg)
Updating Script
11
© Sekolah Tinggi Teknik Surabaya
![Page 12: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/12.jpg)
Select 1.000.000 Element
12
© Sekolah Tinggi Teknik Surabaya
» List is 4 times faster than array when selecting its element.
![Page 13: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/13.jpg)
Selecting Script
13
© Sekolah Tinggi Teknik Surabaya
![Page 14: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/14.jpg)
When We Use Array ?» Knowing its size, and its size rarely
change» Just do basic thing with its element
14
© Sekolah Tinggi Teknik Surabaya
![Page 15: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/15.jpg)
When We Use List ?» Wanting a dynamic array» Need a lot of function built in˃ Need to remove one or more of its
element˃ AddRange function
15
© Sekolah Tinggi Teknik Surabaya
![Page 16: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/16.jpg)
Exercise» Let’s create List class with array !
16
© Sekolah Tinggi Teknik Surabaya
![Page 17: List Eka, Erick, Reddy © Sekolah Tinggi Teknik Surabaya 1.](https://reader035.fdocuments.in/reader035/viewer/2022062421/56649c8a5503460f94944a6a/html5/thumbnails/17.jpg)
Reference» Arrays Tutorial,
http://msdn.microsoft.com/en-us/library/aa288453(v=vs.71).aspx, accessed on April 5th 2014.
» C# List, http://www.dotnetperls.com/list, accessed on April 5th 2014.
17
© Sekolah Tinggi Teknik Surabaya