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; ...
Posts
Showing posts from January, 2022
- Get link
- X
- Other Apps
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(){ ...
- Get link
- X
- Other Apps
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("...