List data structure |
|
|
|||
This is a new data structure for you.
The List data structure is among
the most generic of data structures. In daily life, we use shopping list, groceries
list, list of people to invite to a dinner, list of presents to give etc. In
this course, we will see how we use lists in programming. A list is the collection of items of the
same type (grocery items, integers, names). The data in arrays are also of
same type. When we say int x[6]; it
means that only the integers can be stored in it. The same is true for list.
The data which we store in list should be of same nature. The items, or
elements of the list, are stored in some particular order. What does this
mean? Suppose in the list, you have the fruit first which are also in some
order. You may have names in some alphabetical order i.e. the names which
starts with A should come first
followed by the name starting with B
and so on. The order will be reserved when
you enter data in the list. It is possible to insert new elements
at various positions in the list and remove any element of the list. You have
done the same thing while dealing with arrays. You enter the data in the
array, delete data from the array. Sometimes the array size grows and at
times, it is reduced. We will do this with the lists too. List is a set of elements in a linear
order. Suppose we have four names a1,
a2, a3, a4 and their order is as (a3,
a1, a2, a4) i.e. a3, is the
first element, a1 is the second
element, and so on. We want to maintain that order in the list when data is
stored in the list. We don’t want to disturb this order. The order is
important here; this is not just a random collection of elements but an ordered one. Sometimes, this order is
due to sorting i.e. the things that start with A come first. At occasions, the order may be due to the
importance of the data items. We will discuss this in detail while dealing
with the examples. |
|||||
|
BACK |
HOME |
NEXT |
||