Module 2(Linked List)
Module 2(Linked List)
101009/IT200C (Module 2)
S2 CU
Tinku Soman Jacob
Asst. Prof IT
RSET
1
Index
• Self referential structure
• Dynamic memory allocation
• Linked list
• Single linked list
• Doubly linked list
• Circular linked list
• Stack and queue using linked list
• Polynomial representation using linked list
• x=10
• ptr=&x
• y=*ptr
• *ptr=25
6
101009/IT200C _S2 CU_Module-2 Mr. Tinku Soman Jacob, DIT, RSET(Autonomous)
Memory Allocation
• To execute a program, memory for the required data should be allocated to the
- Neil Armstrong
•program.
• Two methods for memory allocation.
• Static memory allocation
• Memory is allocated at compile time.
• Exact size of memory of each variable must be know.
• Stack is used to implement static memory allocation
• Memory cannot be increased while executing the program.
• Dynamic Memory Allocation
• Memory is allocated at run time.
• Depends on the program need memory is allocated at run time.
• Pointers are used for the implementation.
• Heap is used to implement dynamic memory allocation.
• It is the free memory that can be used at run time.
101009/IT200C _S2 CU_Module-2 Mr. Tinku Soman Jacob, DIT, RSET(Autonomous)
Dynamic Memory Allocation Functions
1.malloc()
2.calloc()
3.realloc()
4.free()
17
Linked list- Structure definition
Array Linked List Linked List
struct node struct node struct student
{ { {
int info; char name[10];
int info;
int next; int rollno;
struct node *next;
int mark[3],total;
}; }; struct student * next;
struct node list[12]; struct node * start; };
struct node *start=NULL;
}
while b!=NULL
{
result(b->coef,b->exp)
b=b->next
}
}//end of poly add
58