Posts

 Sort singly linked list: /******************************************************************************                             Online C Compiler.                 Code, Compile, Run and Debug C program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <stdio.h> #include <stdlib.h> struct Node {     int data;     struct Node* next; }; void push(int element, struct Node* head){  struct Node* temp = head;  struct Node* newNode;  newNode =(struct Node *)malloc(1*sizeof(struct Node));  newNode->data = element;  newNode->next = NULL;  while(temp->next){  temp = temp->next;  }  temp->next = newNode; } void sort(struct Node* head){     struct Node *...
 DS Lab: 17-01-2021 #include <stdio.h> #include <stdlib.h> struct Node{     int data;     struct Node* next;     struct Node* prev; };  struct Node* head = NULL;  struct Node* currentNode;     // head = (struct Node* ) malloc(sizeof(struct Node));     //  currentNode = (struct Node* ) malloc(sizeof(struct Node)); void traversal(){     struct Node* temp;     temp = head;     while(temp !=  NULL){         printf("%d \n", temp->data);         temp = temp->next;     } } void addNode(int userData){     struct Node* newNode;     newNode = (struct Node* ) malloc(sizeof(struct Node));     newNode->data = userData;     newNode->next = NULL;     newNode->prev = NULL;     if(head == NULL){         head = newNode;        ...
 OOM- 05/2022 Example and types of inheritance: #include <iostream> using namespace std; class Animal{     public:     void isAnimal(){         cout << "I'm an animal \n";      } }; class Homosapiens{     public:     void legs(){         cout << "I've 2 legs \n";     } }; class Reptile{     public:     void isReptile(){         cout << "I'm a reptile \n";     } }; class Snake: public Animal, public Reptile{     public:     void isSnake(){         cout << "I'm a snake \n";     } }; class Human :public Animal, public Homosapiens{     public:     void isHuman(){         cout << "I'm a Human \n";     } }; class Child: public Human {     public:     void isChild(){     ...
 DSA: 03-Jan 1) Linear search // linear search #include <stdio.h> int main() {     int size=0;     int index = -1;     int element;     printf("Enter size of array: ");     scanf("%d", &size);     printf("Enter elements of array: ");     int arr[size];     int i=0;     for(i=0; i< size; i++){         scanf("%d", &arr[i]);         // printf("Elements of arr: %d", arr[i]);     }     printf("Element to search:");     scanf("%d", &element);     for(i=0; i< size; i++){         if(arr[i] == element){             index = i;             printf("element found at index%d", index);             return index;         }     }          printf("...

DSA lab: 27-Dec-21

Code implementation for: 1) Print hello world #include <stdio.h> int main() {     printf("Hello World");     return 0; } 2) Sum of two number   #include <stdio.h> int sum(){     int num1, num2, sum;        printf("enter first number:");     scanf("%d", &num1);     printf("enter second number:");     scanf("%d", &num2);     sum = num1 + num2;     printf("sum is: %d", sum); } int main() {          sum();     return 0; } 3) Sum of array's elements #include <stdio.h> int main() {     int sizeArr;     printf("Enter size of arr: ");    scanf("%d", &sizeArr);    int arr[sizeArr];    printf("Enter elements of arr: ");    for(int i=0;i<sizeArr;i++){        scanf("%d", &arr[i]);    }    int sum=0; // why initialized wit...