├── 0. Pointers └── pointers.c ├── 1. Array Operations ├── 0. Creation & Traversal │ └── creation_traversal_2D_array.c ├── 1. Insertion │ └── array_insertion_traversal.c ├── 2. Deletion │ └── deletion_from_array.c ├── 3. String Operations │ ├── string_reversal.c │ └── total_length_string.c ├── 4. Searching │ ├── binary_search.c │ ├── binary_search_function.c │ ├── interpolation.c │ └── linear_search.c └── 5. Sorting │ ├── bubble_sort.c │ ├── insertion_sort.c │ ├── quick_sort.c │ ├── selection_sort.c │ └── shell_sort.c ├── 3. Stacks ├── 0. Stack Operation.c └── 1. Stack Using Array.c ├── 4. Queue ├── 0. queue_operation.c ├── 1. circular_queue.c └── 2. priority_queue.c └── 5. Linked List ├── 0. simple_linked_list └── 1. linked_list_operations.c /0. Pointers/pointers.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main() 4 | { 5 | 6 | // Implementation of Pointers in c: 7 | int a=10; 8 | int *pointer=&a; 9 | printf("Simple Pointer: %d\n",*pointer); 10 | 11 | // Implementation of NULL Pointers in c: 12 | int b=10; 13 | int *null_pointer=NULL; 14 | 15 | // Implementation of VOID Pointers in c: 16 | int c=10; 17 | void *void_pointer=&c; 18 | printf("Void Pointer: %d\n",*(int*)(void_pointer)); 19 | 20 | 21 | // Implementation of WILD Pointers in c: 22 | int d=20; 23 | int *wild_pointer; 24 | printf("Wild Pointer: %d\n",*wild_pointer); 25 | 26 | //Implementation of Dangling Pointer in c: 27 | int *dangling_pointer= (int*)(malloc(sizeof(int))); 28 | free(dangling_pointer); //Deleting the pointer from memory 29 | printf("Dangling Pointer: %d\n",*dangling_pointer); //Even after deletion it shows random value 30 | 31 | //Implementaion of Complex Pointer: 32 | int (*complex_pointer)[8]; 33 | 34 | //Implementaion of Near Pointer: 35 | int x = 42; 36 | int near * ptr = & x; 37 | int sz = sizeof(ptr); 38 | printf("size of ptr is %d byte", sz); 39 | 40 | //Implementaion of Far Pointer: 41 | int x = 42; 42 | int near * far = & x; 43 | int sz = sizeof(ptr); 44 | printf("size of ptr is %d byte", sz); 45 | 46 | //Implementaion of Huge Pointer: 47 | char huge * far *p; 48 | printf("%d %d %d",sizeof(p),sizeof(*p),sizeof(**p)); 49 | 50 | } 51 | -------------------------------------------------------------------------------- /1. Array Operations/0. Creation & Traversal/creation_traversal_2D_array.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int rows=0; 4 | int cols=0; 5 | printf("ENTER THE NO OF ROWS IN ARRAY:\n"); 6 | scanf("%d",&rows); 7 | printf("ENTER THE NO OF COLUMNS IN ARRAY:\n"); 8 | scanf("%d",&cols); 9 | int arr[rows][cols]; 10 | 11 | for(int i=0;i 2 | int main(){ 3 | int size=0; 4 | printf("ENTER THE SIZE OF ARRAY:\n"); 5 | scanf("%d",&size); 6 | int arr[size]; 7 | 8 | //array insertion 9 | for(int i=0;i 2 | int main(){ 3 | int size=0; 4 | printf("ENTER THE SIZE OF ARRAY:\n"); 5 | scanf("%d",&size); 6 | int arr[size]; 7 | 8 | for(int i=0;i 2 | int main(){ 3 | char str[100]; 4 | int i=0,count=0; 5 | char str2[100]; 6 | printf("Enter the string:\n"); 7 | scanf("%s",str); 8 | while(str[i]!='\0'){ 9 | count++; 10 | i++; 11 | } 12 | int j=0; 13 | for(int i=count-1;i>=0;i--){ 14 | str2[j]=str[i]; 15 | j++; 16 | } 17 | 18 | printf("%s",str2); 19 | 20 | } -------------------------------------------------------------------------------- /1. Array Operations/3. String Operations/total_length_string.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | char str[100]; 4 | int i=0,count=0; 5 | printf("Enter the string:\n"); 6 | scanf("%s",str); 7 | while(str[i]!='\0'){ 8 | count++; 9 | i++; 10 | } 11 | printf("Total Length of String: %d",count); 12 | } -------------------------------------------------------------------------------- /1. Array Operations/4. Searching/binary_search.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main(){ 3 | int arr[]={1,2,3,4,5}; 4 | int element=5; 5 | int start=0; 6 | int count=0; 7 | int stop=sizeof(arr)/sizeof(int); 8 | 9 | while(1){ 10 | int mid=start+(stop-start)/2; 11 | if(arr[mid]==element){ 12 | printf("%d",mid); 13 | break; 14 | } 15 | else if(arr[mid]>element){ 16 | stop=mid-1; 17 | } 18 | else if(arr[mid]stop){ 23 | printf("ELEMENT NOT PRESENT IN THE ARRAY"); 24 | break; 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /1. Array Operations/4. Searching/binary_search_function.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int bs(int arr[],int start,int stop,int element){ 4 | if(stop>=start){ 5 | int mid=start+(stop-start)/2; 6 | if(arr[mid]==element){ 7 | return mid; 8 | } 9 | else if(arr[mid]>element){ 10 | return bs(arr,start,mid-1,element); 11 | } 12 | else if(arr[mid] 2 | int main() 3 | { 4 | int arr[] = { 10, 12, 13, 16, 18, 19, 20, 21, 5 | 22, 23, 24, 33, 35, 42, 47 }; 6 | int n = sizeof(arr) / sizeof(arr[0]); 7 | int x = 23; 8 | int start=0; 9 | int stop=n-1; 10 | int pos; 11 | int count=0; 12 | while(1){ 13 | if (start <= stop && x >= arr[start] && x <= arr[stop]) { 14 | 15 | pos=start + ((x-arr[start])*((double)(stop-start))/(arr[stop]-arr[start])); 16 | if(arr[pos]==x){ 17 | printf("The element is present in index: %d",pos); 18 | break; 19 | 20 | } 21 | if(arr[pos]x){ 25 | stop=pos-1; 26 | } 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /1. Array Operations/4. Searching/linear_search.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | int main(){ 5 | int size=0; 6 | printf("ENTER THE SIZE OF ARRAY:\n"); 7 | scanf("%d",&size); 8 | int arr[size]; 9 | 10 | //array insertion 11 | for(int i=0;i 2 | int main(){ 3 | int arr[]={10,77,1,5,100,20,6,99}; 4 | int size=sizeof(arr)/sizeof(int); 5 | int temp; 6 | for(int i=0;i arr[j+1]){ 9 | temp = arr[j]; 10 | arr[j] = arr[j+1]; 11 | arr[j+1] = temp; 12 | } 13 | } 14 | } 15 | for(int i=0;i 2 | 3 | int main() { 4 | int arr[]={5,1,10,4,3,2,45,33,27}; 5 | int temp,j; 6 | int size=sizeof(arr)/sizeof(int); 7 | int count=0; 8 | for(int i=1;i=0&&arr[j]>temp;j--){ 12 | arr[j+1]=arr[j]; 13 | } 14 | arr[j + 1] = temp; 15 | } 16 | 17 | for(int i=0;i 2 | void quicksort(int arr[25],int start,int stop){ 3 | int i, j, pivot, temp; 4 | if(startarr[pivot]) 12 | j--; 13 | if(i 2 | int main() { 3 | int arr[]={5,1,10,4,3,22,21,18}; 4 | int temp,min_idx; 5 | int size=sizeof(arr)/sizeof(int); 6 | for(int i=0;i 2 | 3 | int main() { 4 | int arr[] = {10,9,6,4,1,7,5}; 5 | int size = sizeof(arr) / sizeof(int); 6 | int i,j,temp,gap; 7 | for(gap=size/2; gap>0; gap=gap/2) { 8 | for(i=gap; i=gap && arr[j-gap]>temp; j=j-gap) { 11 | arr[j]=arr[j-gap]; 12 | } 13 | arr[j] = temp; 14 | } 15 | } 16 | printf("Sorted arr: \n"); 17 | for (int i = 0; i < size;i++) { 18 | printf("%d ", arr[i]); 19 | } 20 | } -------------------------------------------------------------------------------- /3. Stacks/0. Stack Operation.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int n, top = -1, *stack; 5 | 6 | void push(int x){ 7 | if(top==n){ 8 | return; 9 | } 10 | stack[++top]=x; 11 | } 12 | 13 | int pop(){ 14 | if(top==-1){ 15 | return -1; 16 | } 17 | return stack[top--]; 18 | } 19 | 20 | int peek(){ 21 | if(top==-1){ 22 | return -1; 23 | } 24 | return stack[top]; 25 | } 26 | 27 | void display(){ 28 | for(int i=top ; i>-1 ; i--){ 29 | printf("%d ",stack[i]); 30 | } 31 | printf("\n\n"); 32 | } 33 | 34 | int main(){ 35 | n = 10; 36 | printf("Initializing the stack with size 10\n\n"); 37 | stack = (int*) malloc(n*sizeof(int)); 38 | printf("Pushing elements into the stack\n1\n2\n3\n\n"); 39 | push(1); 40 | push(2); 41 | push(3); 42 | printf("Displaying elements of the stack -\n"); 43 | display(); 44 | printf("The top of the stack = %d\n\n",peek()); 45 | printf("Pop the top of the stack = %d\n\n",pop()); 46 | printf("Pop the top of the stack = %d\n\n",pop()); 47 | printf("Displaying elements of the stack -\n"); 48 | display(); 49 | } -------------------------------------------------------------------------------- /3. Stacks/1. Stack Using Array.c: -------------------------------------------------------------------------------- 1 | #include 2 | int stack[10], top = -1; 3 | void push(int value){ 4 | if(top == 10-1) 5 | printf("\nStack is Full! Insertion is not possible."); 6 | else{ 7 | top++; 8 | stack[top] = value; 9 | printf("\nEntered Successfully"); 10 | } 11 | } 12 | void pop(){ 13 | if(top == -1) 14 | printf("\nStack is Empty! Deletion is not possible."); 15 | else{ 16 | printf("\nDeleted : %d", stack[top]); 17 | top--; 18 | } 19 | } 20 | void display(){ 21 | if(top == -1) 22 | printf("\nStack is Empty!"); 23 | else{ 24 | int i; 25 | printf("\nStack elements are:\n"); 26 | for(i=top; i>=0; i--){ 27 | printf("%d\n",stack[i]); 28 | } 29 | 30 | } 31 | } 32 | 33 | main() 34 | { 35 | push(20); 36 | push(10); 37 | push(30); 38 | push(40); 39 | display(); 40 | pop(); 41 | display(); 42 | 43 | } 44 | -------------------------------------------------------------------------------- /4. Queue/0. queue_operation.c: -------------------------------------------------------------------------------- 1 | #include 2 | int main() 3 | { 4 | int front=0,rear=0,i,j=1,size,ch; 5 | printf("ENTER THE SIZE OF QUEUE"); 6 | scanf("%d",&size); 7 | int queue[size]; 8 | printf("\n1.Insertion \n2.Deletion \n3.Display \n4.Exit"); 9 | while(1) 10 | { 11 | printf("\nEnter the Choice:"); 12 | scanf("%d",&ch); 13 | switch(ch) 14 | { 15 | case 1: 16 | if(rear==size) 17 | printf("\n Queue is Full"); 18 | else 19 | { 20 | printf("\n Enter no %d:",j++); 21 | scanf("%d",&queue[rear++]); 22 | } 23 | break; 24 | case 2: 25 | if(front==rear) 26 | { 27 | printf("\n Queue is empty"); 28 | } 29 | else 30 | { 31 | printf("\n Deleted Element is %d",queue[front++]); 32 | } 33 | break; 34 | case 3: 35 | printf("\nQueue Elements are:\n "); 36 | if(front==rear) 37 | printf("\n Queue is Empty"); 38 | else 39 | { 40 | for(i=front; i 2 | int main() 3 | { 4 | int front=0,rear=0,i,j=1,size,ch; 5 | printf("ENTER THE SIZE OF QUEUE"); 6 | scanf("%d",&size); 7 | int queue[size]; 8 | printf("\n1.Insertion \n2.Deletion \n3.Display \n4.Exit"); 9 | while(1) 10 | { 11 | printf("\nEnter the Choice:"); 12 | scanf("%d",&ch); 13 | switch(ch) 14 | { 15 | case 1: 16 | if(rear==size) 17 | printf("\n Queue is Full"); 18 | else 19 | { 20 | printf("\n Enter no %d:",j++); 21 | scanf("%d",&queue[rear++]); 22 | } 23 | break; 24 | case 2: 25 | if(front==rear) 26 | { 27 | printf("\n Queue is empty"); 28 | } 29 | else 30 | { 31 | printf("\n Deleted Element is %d",queue[front++]); 32 | if(front==rear){ 33 | front=0; 34 | rear=0; 35 | j=1; 36 | } 37 | } 38 | break; 39 | case 3: 40 | printf("\nQueue Elements are:\n "); 41 | if(front==rear) 42 | printf("\n Queue is Empty"); 43 | else 44 | { 45 | for(i=front; i 2 | int main() 3 | { 4 | int front=0,rear=0,i,j=1,size,ch,element,k; 5 | printf("ENTER THE SIZE OF QUEUE"); 6 | scanf("%d",&size); 7 | int queue[size]; 8 | printf("\n1.Insertion \n2.Deletion \n3.Display \n4.Exit"); 9 | while(1) 10 | { 11 | printf("\nEnter the Choice:"); 12 | scanf("%d",&ch); 13 | switch(ch) 14 | { 15 | case 1: 16 | if(rear==size) 17 | printf("\n Queue is Full"); 18 | else 19 | { 20 | printf("\n Enter no %d:",j++); 21 | scanf("%d",&queue[rear++]); 22 | } 23 | break; 24 | case 2: 25 | if(front==rear) 26 | { 27 | printf("\n Queue is empty"); 28 | } 29 | else 30 | { 31 | printf("ENTER THE ELEMENT YOU WANT TO DELETE FROM THE QUEUE"); 32 | scanf("%d",&element); 33 | for(i=0;i 2 | #include 3 | 4 | struct node{ 5 | int data; 6 | struct node *next; 7 | }; 8 | 9 | struct node *head=NULL; 10 | 11 | main(){ 12 | 13 | int limit,element; 14 | printf("ENTER THE NUMBER OF ELEMENTS YOU WANT TO INSERT:\n"); 15 | scanf("%d",&limit); 16 | 17 | for(int i=0;idata=element; 22 | link->next=head; 23 | head=link; 24 | } 25 | struct node *temp=head; 26 | while(temp!=NULL){ 27 | printf("%d ",temp->data); 28 | temp=temp->next; 29 | } 30 | } -------------------------------------------------------------------------------- /5. Linked List/1. linked_list_operations.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | struct node { 5 | int data; 6 | struct node *next; 7 | }; 8 | 9 | struct node *head = NULL; 10 | 11 | void display() { 12 | struct node *ptr = head; 13 | printf("\n[head] =>"); 14 | while(ptr != NULL) { 15 | printf(" %d =>",ptr->data); 16 | ptr = ptr->next; 17 | } 18 | printf(" [null]\n"); 19 | } 20 | 21 | void insert(int data) { 22 | struct node *link = (struct node*) malloc(sizeof(struct node)); 23 | link->data = data; 24 | link->next = head; 25 | head = link; 26 | } 27 | 28 | void del(){ 29 | // struct node* temp = head; 30 | // while(temp->next->next!=NULL){ 31 | // temp = temp->next; 32 | // } 33 | // temp->next = NULL; 34 | 35 | head=head->next; 36 | 37 | } 38 | 39 | int main() { 40 | int size,element; 41 | printf("Enter the number of elements you want to insert in linked list\n"); 42 | scanf("%d",&size); 43 | for(int i=0;i