You are on page 1of 16

STACK USING LINKED LIST

Need of CO Attainment
Need of CO Attainment
How to push elements in stack using linked list
Need of CO Attainment
• Stack using LL
1. Create structure
struct node
{
int data;
struct node *ptr;
} *top=NULL;
How to push elements in stack using linked list
Need of CO Attainment
2. Write Push function
void push (int item)
{
if (top==NULL)
{
allocate memory to top
top->data=item
top->ptr=NULL
}
How to push elements in stack using linked list
Need of CO Attainment
Else
{
allocate memory to temp;
temp->data=item
temp->ptr=top
top=temp;
}
How to POP elements in stack using linked list
Need of CO Attainment
1. If top =NULL print Underflow
2. Store top->data in item and print it as
deleted element
3. top1=top
4. top=top->ptr
5. Free(top1)
Display Stack
Need of CO Attainment
Void display()
{
top1=top;
while(top1!=NULL)
{
print top1 data;
top1=top->ptr;
}
}
QUEUE USING LINKED LIST
Need of CO Attainment
Need of CO Attainment

SPARSE MATRIX
Need of CO Attainment
Need of CO Attainment
 Sparse matrix is a matrix which contains very
few non-zero elements.
 When a sparse matrix is represented with a 2-
dimensional array, we waste a lot of space to
represent that matrix.
 For example, consider a matrix of size 100 X
100 containing only 10 non-zero elements.
SPARSE OR DENSE???
Need of CO Attainment
SPARSE MATRIX using Array
Need of CO Attainment
SPARSE MATRIX using
Need of CO Attainment LL
Link
Need of CO Attainment

https://www.geeksforgeeks.org/sparse-matrix-r
epresentation/
ACTIVITY
Need of CO Attainment

https://gatetestseries.in/cs-programming-data-s
tructures/linked-list/ll-online-test-1/

You might also like