Posts

21

 import pytest def power(x, y, expected):     assert x ** y == expected @pytest.mark.parametrize("x, y, expected", [     (2, 2, 4),     (2, 3, 8),     (1, 9, 1),     (0, 9, 0), ]) def test_power(x, y, expected):     power(x, y, expected)

Bst

 #include <stdio.h> #include <stdlib.h> // Structure definition for a BST node typedef struct Node {     int data;     struct Node *left, *right; } Node; // Function prototypes Node* createNode(int data); Node* insert(Node* root, int data); Node* deleteNode(Node* root, int data); Node* minValueNode(Node* node); Node* search(Node* root, int data); void inorderTraversal(Node* root); void menu(); int main() {     Node* root = NULL;     int choice, data;     while (1) {         menu();         printf("Enter your choice: ");         scanf("%d", &choice);         switch (choice) {             case 1:                 printf("Enter the data to insert: ");                 scanf("%d", &data);             ...

Th

 #include <stdio.h> #include <stdlib.h> typedef struct ThreadedNode {     int data;     struct ThreadedNode *left, *right;     int rightThread; // 1 if right pointer is a thread, otherwise 0 } ThreadedNode; // Function prototypes ThreadedNode* createNode(int data); ThreadedNode* insert(ThreadedNode* root, int data); ThreadedNode* leftMost(ThreadedNode* node); void inorderTraversal(ThreadedNode* root); void menu(); int main() {     ThreadedNode* root = NULL;     int choice, data;     while (1) {         menu();         printf("Enter your choice: ");         scanf("%d", &choice);         switch (choice) {             case 1:                 printf("Enter the data to insert: ");                 scanf("%d", &data); ...

Form

 #include <stdio.h> #include <stdlib.h> #define MAX 100 int tree[MAX]; // Function prototypes void insertNode(int data); void preorderTraversal(int index); void inorderTraversal(int index); void postorderTraversal(int index); void menu(); int main() {     int choice, data;     // Initialize the tree array with -1 indicating empty nodes     for (int i = 0; i < MAX; i++) {         tree[i] = -1;     }     while (1) {         menu();         printf("Enter your choice: ");         scanf("%d", &choice);         switch (choice) {             case 1:                 printf("Enter the data to insert: ");                 scanf("%d", &data);                 insertNode(data); ...