Posts

Showing posts with the label linked

Stack implementation through Linked list in C

Image
Stack implementation through Linked list in C We can avoid the size limitation of a stack implemented with an array, with the help of a linked list to hold the stack elements. As needed in case of array, we have to decide where to insert elements in the list and where to delete them so that push and pop will run at the fastest. Primarily, there are two operations of a stack; push() and pop() . A stack carries lifo behavior i.e. last in, first out. You know that while implementing stack with an array and to achieve lifo behavior, we used push and pop elements at the end of the array. Instead of pushing and popping elements at the beginning of the array that contains overhead of shifting elements towards right to push an element at the start and shifting elements towards left to pop an element from the start. To avoid this overhead of shifting left and right, we decided to push and pop elements at the end of the array. Now, if we use linked list to implement the stack, where wi...

Sorted Linked List implementation in C

Sorted Linked List implementation in C include "stdio.h" include "stdlib.h" include "conio.h" void del(int data); void insert(int value); void display(); struct node {     int data;     struct node *link; }; struct node *top=NULL,*temp, *temp1, *temp2, *temp3; int main() {     int choice,data;       while(1) //infinite loop is used to insert/delete infinite number of elements in linked list     {               printf(" 1.Insert 2.Delete 3.Display 4.Exit ");         printf(" Enter ur choice:");         scanf("%d",&choice);         switch(choice)         {         case 1:                                 printf("Enter a new element :");             scanf("%d",&data);      ...