10.09.2013 Views

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

1. Advanced Data Structure using C++

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LECTURE NOTES OF ADVANCED DATA STRUCTURE (MT-CSE 110)<br />

TYPES OF ARRAYS<br />

One‐dimensional arrays<br />

The one dimensional arrays are also known as Single dimension array and are a<br />

type of Linear Array. In the one dimension array the data type is followed by the<br />

variable name which is further followed by the single subscript i.e. the array can<br />

be represented in the row or column wise. It contains a single subscript that is<br />

why it is known as one dimensional array because one subscript can either<br />

represent a row or a column.<br />

For example auto int new[10];<br />

In the given example the array starts with auto storage class and is of integer<br />

type named new which can contain 10 elements in it i.e. 0‐9. It is not necessary<br />

to declare the storage class as the compiler initializes auto storage class by<br />

default to every data type After that the data type is declared which is followed<br />

by the name i.e. new which can contain 10 entities.<br />

For a vector with linear addressing, the element with index i is located at the<br />

address B + c ∙ i, where B is a fixed base address and c a fixed constant,<br />

sometimes called the address increment or stride.<br />

If the valid element indices begin at 0, the constant B is simply the address of<br />

the first element of the array. For this reason, the C programming language<br />

specifies that array indices always begin at 0; and many programmers will call<br />

that element "zeroth" rather than "first".<br />

However, one can choose the index of the first element by an appropriate<br />

choice of the base address B. For example, if the array has five elements,<br />

indexed 1 through 5, and the base address B is replaced by B − 30c, then the<br />

indices of those same elements will be 31 to 35. If the numbering does not start<br />

at 0, the constant B may not be the address of any element.<br />

Prepared By :­<br />

Er. Harvinder Singh<br />

Assist Prof., CSE, H.C.T.M (Kaithal) Page ‐ 33 ‐

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!