4 Year Department Of
th
Information Technology
ID No: TER/3503/04
datatype arrayname[];
Example:
double myList[];
Conn(…)
Limitations of array
Once an array is created, its size cannot be altered.
Array provides inadequate support for inserting, deleting,
sorting, and searching operations.
What are Advantages and Disadvantages of arrays?
Advantages:
Disadvantages:
1. We must know in advance that how many elements are to be
stored in array.
2. Array is static structure. It means that array is of fixed size. The
memory which is allocated to array can not be increased or reduced.
3. Since array is of fixed size, if we allocate more memory than
requirement then the memory space will be wasted. And if we
allocate less memory than requirement, then it will create problem.
4. The elements of array are stored in consecutive memory locations.
So insertions and deletions are very difficult and time consuming.
.Linked List
Linked list is an ordered collection of
element s called nodes which has two parts.
.The nodes connected by pointer.
Head Data Pointer Data Pointer Data \
What is the difference between
Linked List and Linear Array?
Array
Insertions and deletions are difficult.
It needs movements of elements for insertion and deletion.
In it space is wasted.
It is more expensive.
It requires less space as only information is stored.
Its size is fixed.
Conn(….)
char ID[4];
char name[20];
float CGPA;
STUDENOD*Next;
};
Advantages and Disadvantages of linked list
void FloatList::displayList(void)
{
ListNode *nodePtr;
nodePtr = head;
while (nodePtr)
{
cout << nodePtr->value << endl;
nodePtr = nodePtr->next;
}
}
4. Adding a Node
There are four steps to add a node to a linked list: