list eka, erick, reddy © sekolah tinggi teknik surabaya 1

Post on 14-Dec-2015

226 Views

Category:

Documents

8 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Data Structure

ListEka, Erick, Reddy

© Sekolah Tinggi Teknik Surabaya

1

Array» Fixed Size» Initialization: int[] abc = new int[10];

» Accessing by its index int tmp = abc[0];

2

© Sekolah Tinggi Teknik Surabaya

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

Array Vs List (1)

4

© Sekolah Tinggi Teknik Surabaya

» Size˃ ArrayFixed Size, but you can use Array.Resize˃ ListDynamic Size

Array Vs List (2)» Dimension˃ Array : Support multi dimensionExample :

˃ List : One DimensionBut we can make it multi too

5

© Sekolah Tinggi Teknik Surabaya

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

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

Insert 1.000.000 Element

8

© Sekolah Tinggi Teknik Surabaya

» List is slower than Array when inserting, because List resize its length first

Inserting Script

9

© Sekolah Tinggi Teknik Surabaya

Update 1.000.000 Element

10

© Sekolah Tinggi Teknik Surabaya

» When updating its element, list is much faster than array.

Updating Script

11

© Sekolah Tinggi Teknik Surabaya

Select 1.000.000 Element

12

© Sekolah Tinggi Teknik Surabaya

» List is 4 times faster than array when selecting its element.

Selecting Script

13

© Sekolah Tinggi Teknik Surabaya

When We Use Array ?» Knowing its size, and its size rarely

change» Just do basic thing with its element

14

© Sekolah Tinggi Teknik Surabaya

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

Exercise» Let’s create List class with array !

16

© Sekolah Tinggi Teknik Surabaya

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

top related