C++ and Intro to Arrays and LinkedList

C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs.

C++ is an extension of the C programming language which supports the creation of Classes and hence it is Known as "C with classes".

*Before we get into Stacks , Queues , Sorting , You must have Knowledge about Arrays and Linkedlist*

ARRAYS

Array is a Data Structure of fixed size . It holds items of the same Datatype.All arrays consist of contiguous memory locations. The lowest address corresponds to the first element and the highest address to the last element. Arrays are zero indexed.

Declaration of ARRAYS

It is declared like 

type arrayName [ arraySize ];
int arr[10];

Initializing ARRAYS

While initializing you should keep in mind to not make the number of terms more than the size of the array.

 

int arr[5] = {12,22,18,14,30};

 

Accessing ARRAYS

int new = arr[3];

here we are accessing the 3rd element of array .

Linked List

A linked list is a sequential structure that consists of sequence of items in linear order which are linked to each other. There is no fixed size in Linked list. It has Dynamic allocations of data.

Here the Node will carry the pointers to next item and Previous item.

Advantages of Linked List Over Arrays

  1. The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage.
  2. Inserting a new element in an array of elements is expensive because the room has to be created for the new elements and to create room existing elements have to be shifted.

Advantages of Arrays over Linked List

  1. Random access is not allowed. We have to access elements sequentially starting from the first node. So we cannot do binary search with linked lists efficiently with its default implementation.
  2. Extra memory space for a pointer is required with each element of the list.
  3. Not cache friendly. Since array elements are contiguous locations, there is locality of reference which is not there in case of linked lists.

 

*We Will Be Using Arrays , So for Now lets not get deep into linked list*

 

Discussion
best platform

1

Great platform 🙂🙂🙂🙂

2

Great Bro Helps me a lot Thanks

2

21

3