Skip to main content

Posts

Linked List

 Linked List:                      A linked list is a linear data structure, in which the elements are not stored at contiguous memory locations. Why Linked List?  Arrays can be used to store linear data of similar types, but arrays have the following limitations.  1) The size of the arrays is fixed: So we must know the upper limit on the number of elements in advance. Also, generally, the allocated memory is equal to the upper limit irrespective of the usage.  2) Inserting a new element in an array of elements is expensive because the room has to be created for the new elements and to create room existing elements have to be shifted.  For example, in a system, if we maintain a sorted list of IDs in an array id[].  id[] = [1000, 1010, 1050, 2000, 2040].  And if we want to insert a new ID 1005, then to maintain the sorted order, we have to move all the elements after 1000 (excluding 1000).  Deletion is also expensive with arrays until unless some special techniques are used. For example
Recent posts

Menu Driven Singly Linked List

Menu Driven Singly Linked List   CODE 👇 #include<stdio.h> #include<stdlib.h> typedef struct node  { int info; struct node *next; }NODE; NODE* createlist(NODE *list);  void Display (NODE *list); void search (NODE *list); NODE* insertbeg(NODE *list); NODE* insertbetween(NODE *list); NODE* insertlast(NODE *list); NODE* Delpos(NODE *list); NODE* Delvalue(NODE *list); //MAIN FUNCTION void main () {     printf(">>Singly Linked List<<"); NODE*list=NULL, *temp;     int ch,n,pos; do { printf("\n1. Create:"); printf("\n2. Display"); printf("\n3.Insert AtFirst"); printf("\n4.Insert AtMiddle"); printf("\n5.Insert AtLast"); printf("\n6. Delete by position"); printf("\n7. Delete by value"); printf("\n8. Search"); printf("\n9.Reverse"); printf("\n10.Count"); printf("\n11. Exit\n"); printf("\n Enter

Addition Of Two Polynomials

Addition Of Two Polynomials. CODE 👇 #include <stdio.h> #include <stdlib.h> typedef struct node { int exp, coef; struct node *next; }P; void create(P *p1); void display(P *p1); void add(P *p1, P *p2, P *p3); void main() { P *p1, *p2, *p3, *p4; p1=(P*)malloc(sizeof(P)); p1->next=NULL; p2=(P*)malloc(sizeof(P)); p2->next=NULL; p3=(P*)malloc(sizeof(P)); p3->next=NULL; p4=(P*)malloc(sizeof(P)); p4->next=NULL; create(p1); printf("1st Polynomial is:\t"); display(p1); printf("\n\n"); create(p2); printf("2nd Polynomial is:\t"); display(p2); printf("\n\n"); add(p1, p2, p3); printf("\n Addition of 1st and 2nd Polynomial is:\n"); display(p1); printf("+"); display(p2); printf("="); display(p3); printf("\n\n"); } void create(P *p1) { P *temp=p1, *nn; int i, n; printf("How many terms you want to enter:"); scanf("%d",

Circular Doubly Linked List

Circular Doubly Linked List CODE 👇 #include <stdio.h> #include <stdlib.h> typedef struct node { int info; struct node *next; struct node *prev; }NODE; void createlist(NODE *list); void display(NODE *list); void search(NODE *list); void insert(NODE *list, int num, int pos); void delpos(NODE *list, int pos); void delvalue(NODE *list, int num); void main() { int pos, num, n, no; NODE *list=(NODE*)malloc(sizeof(NODE)); list->next=list; createlist(list); display(list); printf("\n"); do { printf("\nOperation on Doubly Linked List:"); printf("\n1. Insert:"); printf("\n2. Display"); printf("\n3. Search"); printf("\n4. Delete by position"); printf("\n5. Delete by value"); printf("\n6. Exit\n"); printf("\n Enter your choice:"); scanf("%d", &no); switch(no) { case 1:  printf(" Enter the node data:"

Doubly Linked List

Doubly Linked List CODE 👇 include <stdio.h> #include <stdlib.h> typedef struct node { int info; struct node *prev, *next; }NODE; NODE* createlist(NODE *list); NODE* insert(NODE *list, int num, int pos); void display(NODE *list); NODE* search(NODE *list, int n1); NODE* delpos(NODE *list, int pos); NODE* delvalue(NODE *list, int n2); void main() { int num, n1, n2, n3, pos; NODE *list=NULL, *temp; list=createlist(list); display(list); printf("\nEnter Element to be search:\t"); scanf("%d", &n1); temp=search(list, n1); if(temp!=NULL) printf(">>'%d' is found<<\n",n1); else printf(">>'%d' is not found<<\n",n1); printf("\nEnter the node data to insert node:\t"); scanf("%d", &num); printf("Enter the node position to insert node:\t"); scanf("%d", &pos); list=insert(list,num,pos); display(list); printf("\nEnte

Singly Linked List

Singly Linked List  CODE 👇 #include<stdio.h> #include<stdlib.h> typedef struct node  { int info; struct node *next; }NODE; NODE* createlist(NODE *list);  void Display (NODE *list); void search (NODE *list); NODE* insertbeg(NODE *list); NODE* insertbetween(NODE *list); NODE* insertlast(NODE *list); NODE* Delpos(NODE *list); NODE* Delvalue(NODE *list); void main () { NODE*list=NULL, *temp;        int ch,n,pos; list=createlist (list); Display (list); search (list); list=insertbeg (list); Display (list); list=insertbetween (list); Display (list); list=insertlast (list); Display (list); list=Delpos (list); Display (list); list=Delvalue (list); Display (list); } NODE* createlist (NODE *list) {  int n,count; NODE *temp, *newnode;  printf ("How many nodes you want to enter ? \n");  scanf("%d" ,&n);  for(count=1 ; count<=n; count++)   {   newnode=(NODE*)malloc(sizeof(NODE));  newnode->next=NULL;   printf( "Enter the nod