FUNCTIONS PART-4 WITH ARGUMENT AND NO RETURN TYPE Get link Facebook X Pinterest Email Other Apps June 02, 2024 #include <iostream>using namespace std;void adharsh(int a,int c){ cout<<a+c;}int main(){ adharsh(20,30); return 0;} Get link Facebook X Pinterest Email Other Apps Comments
GLOBAL VARIABLES July 09, 2024 #include<iostream> using namespace std; int a,b; int multiply() { a=198; return 0; } int main() { cout<<"BEFORE PROCESSING " ; a=19; cout<<a<<"\n"; multiply(); cout<<"AFTER PROCESSING "<<a; return 0; } Read more
TREE ORDER TRAVERSAL June 14, 2024 #include <iostream> using namespace std; class Tree { struct Node { string data; // Changed 'type' to 'string' to match the data being inserted Node* left; Node* right; Node(string d) : data(d), left(nullptr), right(nullptr) {} }; public: Node* root = nullptr; Tree() { Node* f = new Node("F"); Node* g = new Node("G"); Node* h = new Node("H"); f->left = g; f->right = h; root = f; // Corrected 'Root' to 'root' } void preorder(Node* ptr) { if (ptr != nullptr) { cout << ptr->data << " "; ... Read more
LIST ADT USING LINKED LIST June 14, 2024 #include <iostream> using namespace std; struct Node { int data; Node* next; }; Node* head = nullptr; void insert() { int value; cout << "\nEnter the element to insert: "; cin >> value; Node* newNode = new Node{value, nullptr}; if (!head) { head = newNode; } else { newNode->next = head; head = newNode; } } void display() { if (!head) { cout << "\nList is empty\n"; return; } Node* temp = head; cout << "\nList elements:\n"; while (temp) { cout << temp->data << " "; temp = temp->next; } cout << "\n"; } int main() { ... Read more
Comments
Post a Comment