Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
02 Arrays And Memory Mapping
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23. void LinearList :: moveForward(int index) { int temp = ListArray[index]; int i = index; while ((i < (size - 1)) && (ListArray[i] > ListArray[i + 1])) { ListArray[i] = ListArray[i+1]; i = i + 1; } if (i != index) ListArray[i] = temp; } void LinearList :: moveBackward(int index) { int temp = ListArray[index]; int i = index; while ((i > 0 ) && (ListArray[i] < ListArray[i - 1])) { ListArray[i] = ListArray[i-1]; i = i - 1; } if (i != index) ListArray[i] = temp; }
24.
Notes de l'éditeur
One of the most common data object is an ordered list. An ordered list has elements with definite ordering. The simplest example of an ordered list is an ordered pair which has only two elements. Following are some examples of ordered lists: Months of the years (Jan, Feb, Mar, Apr, May,…., Dec) English Alphabets (A, B, C, …, Z) Words in a sentence (“This is a book on data structures.”) Names of the students in a class stored in the order of their roll numbers. It may be noted that the elements in an ordered-list must maintain a specified order. For example, changing the orders of words in a sentence will change the sentence. That is, it will no longer be the same sentence. As an abstract data type, an ordered-list will typically support the following operations: Create a new empty list. Delete a list. Find the number of elements in the list or length of the list. Check if the list is empty. Check if more elements can be added to the list or whether the list is full. Traverse the list in some order. Get the i th elements in the list. Change the value of the i th element. Insert a new element at the i th position. Insert a new element according to the specified order. Delete the i th element. The easiest way to represent an ordered list is by an one-dimensional array where we store the i th element of the list in the array element with index i. This is called sequential or linear mapping. That is mapping a one-dimensional vector onto a one-dimensional space.
It is always a very good idea to explicitly keep track of the number elements in a list. This will make your life more comfortable. Your algorithms simpler and will be more independent of the data type stored in your list.