Professional Documents
Culture Documents
Ex.No: 1
Aim:
To write a C program that finds the second largest element in a given list
of N numbers.
Algorithm:
Matrix Operations
Aim:
Algorithm:
Aim:
Algorithm:
Aim:
Algorithm:
Aim:
Algorithm:
1. The deleteK() function takes two argument , head of linked list and an
integer k.
2. To find the ‘k’ the element to delete that node from the linked list find the
size of the linked list (i.e.,number of nodes of linked list) and store the
result in ‘size’
3. copy the head pointer to another pointer called ‘temp’
4. If ‘k’ is greater than size, don’t allow deletion, stop the function. else,
while ‘k’ is lesser than ‘size’, move the temp pointer to the next node and
decrement k.
5. Copy the temp->next to pointer called ‘del’ and update the temp->next to
del->next and remove the del pointer using free(del)
Ex. No: 6
Aim:
Algorithm:
Aim:
Algorithm:
1. Define a structure of node with two elements in it namely data and next to
store the data of each node and address of next node respectively.
2. Create a top pointer to store the address of the top of the stack
3. Initialize the top pointer as NULL to show that the stack is empty
4. Define Push() function with “top” of the list as first argument and data to
be pushed to stack as the second argument.
5. The Push() function creates or dynamically allocates memory and store
the data about to be pushed in that node and make the newly allocated
address as top of the stack
6. The Pop() function copy the top pointer address to “temp” pointer and
move the top pointer to point to next node and free the temp pointer
7. The display() function display the elements present in the stack
Ex. No: 8
Aim:
Algorithm:
1. Get the ‘N’ – size of the list followed by ‘N’ elements from the user.
2. Create a stack to hold ‘N’ elements maximum.
3. Define Push(), Pop(), Display() functions
4. Push the first element to stack
5. Pick rest of the elements one by one from the list and follow the
following steps:
a. Mark the current element as next
b. If stack is not empty, then pop an element from stack and compare
it with next
c. If next is greater than the popped element, then next is the next
greater element for the popped element.
d. Keep popping from the stack while the popped element is smaller
than next. Next becomes the next greater element for all such
popped elements.
e. If next is smaller than the popped element, then push the popped
element back.
6. After the loop in step 5 is over, pop all the elements from the stack and
print -1 as next element for them.
Ex. No: 9
Aim:
Algorithm:
Aim:
Algorithm:
1. Define a structure of node with two elements in it namely data and next to
store the data of each node and address of next node respectively.
2. Create a front pointer to store the address of the first node of the list.
3. Create a rear pointer to store the address of the last node of the list.
4. Initialize the front pointer and rear pointer as NULL to show that the
queue is empty
5. The InsertQ() function creates or dynamically allocates memory and store
the data about to be pushed in that node and make the newly allocated
address as rear of the queue
6. The DeleteQ() function copy the front pointer address to “temp” pointer
and move the front pointer to point to next node and free the temp pointer
7. The DisplayQ() function display the elements present in the Queue.
Ex. No: 11
Aim:
Algorithm: