Notebook


// C++: Bubble Sort Algorithm

#include <iostream>

using namespace std;


int main(){


    int n= 6;

    int arr[n] = {5,-10,7,2,9,0};


    for(int right = n-1; right >=0; right--){

        for(int left = 0; left < right; left++){

            if (arr[left]> arr[left+1]){

                int tmp = arr[left];

                arr[left] = arr[left+1];

                arr[left+1]= tmp;

            }

        }

    }

    for (int i = 0; i<n; i++){

        cout << arr[i];

        cout << ",";

    }

    return 0;


}



// C++: Selection sort algorithm


int main(){

    int n= 6;

    int arr[n]= {5,-10,7,2,9,0};


    for(int left = 0; left<n; left++) {

        int minValIndex =left;

        for(int right = left; right<n; right++){

             if (arr[minValIndex] > arr[right]) {

                 minValIndex = right;

             }

        }

        int tmp = arr[left];

        arr[left] = arr[minValIndex];

        arr[minValIndex] = tmp;

    }

    for(int i = 0; i<n; i++){

        cout << arr[i];

        cout << ",";


    }

    return 0;


}



//C++: Inserion Sort Algorithm


int main(){

    int n = 6;

    int arr[n] = {5,-10,7,2,9,0};


    for(int right = 1; right<n; right++){

        int left = right;

        while (left >= 1 && arr[left]< arr[left-1]){

            int tmp = arr[left];

            arr[left]= arr[left-1];

            arr[left-1]= tmp;


        }

    }

    for(int i = 0; i<n; i++){

        cout << arr[i];

        cout << ",";

    }

    return 0;

}



// C++ Code: Implementation of binary search tree


#include <stdlib.h>

#include <iostream>

using namespace std;


struct Node{

    int data;

    struct Node *left;

    struct Node *right;

};


struct Node *newNode(int value){

    struct Node *node= (struct Node*)malloc(sizeof(struct Node));

    node -> data= value;

    node->left = NULL;

    node-> right = NULL;

    return(node);


}


void preoder (struct Node *root){

    if (root == NULL) return;

    cout << root-> data;

    cout << "\n";

    preoder(root-> left);

    preoder(root->right);


}


struct Node *insert(struct Node *root, int value){

    if(root == NULL){

        return (newNode(value));

    }

    if (root->data > value){

        root-> left= insert(root-> left, value);

    }else if(root->data<value){

        root-> right = insert(root->right, value);

    }

    return(root);


}


int main(){

    struct Node *root= newNode(4);

    insert(root, 2);

    insert(root, 7);

    insert(root, 1);

    insert(root, 3);

    insert(root, 5);


    preoder(root);


}


// C++: Stack implementation (push, pop, peek, isFull, isEmpty, len)

#include <iostream>

#include <limits.h>

using namespace std;


const int size = 10; // max size of stack

int stack[size];

int topIndex = -1;


bool isEmpty() {

    if (topIndex == -1)

        return true;

    return false;

}


bool isFull() {

    if (topIndex >= size-1)

        return true;

    return false;

}


int len() {

    if (topIndex == -1) return 0;

    return (topIndex + 1);

}


int peek() {

    return stack[topIndex];

}


int pop() {

    if (isEmpty()) {

        cout << "Stack is Empty!";

        return INT_MIN; // handle it while calling

    }


    return stack[topIndex--];

}


void push(int data) {

    if (isFull()) {

        cout << "Opps, I can't push coz Stack is full!";

        return;

    }

    stack[topIndex + 1] = data;

    topIndex += 1;

}


int main() {

    push(1);

    push(2);

    push(3);

    push(4);

    push(5);

    push(6);

    push(7);

    push(8);

    push(9);

    push(10);

    cout << peek(); // return top element

    pop(); // remove top and return it

    if (isFull() == true) cout << "Stack Full!";

    if (isEmpty() == true) cout << "Stack Empty!";

    cout << len(); // length of stack

    push(11);

    push(12);

    return 0;

}


// C++: Queue implementation (enqueue, dequeue, peek, isFull, isEmpty, len)

#include <iostream>

#include <limits.h>

using namespace std;


const int size = 10; // max size of queue

int queue[size];

int front = 0, rear = 0;


bool isEmpty() {

    if (front == rear)

        return true;

    return false;

}


bool isFull() {

    if (rear == size)

        return true;

    return false;

}


int len() {

    if (isEmpty()) return 0;

    return (rear - front);

}


void enqueue(int val) { // insert into queue

    if (isFull()) {

        cout << "Oops! Queue is full!";

        return;

    };


    queue[rear++] = val;

}


int peek() {

    if (isEmpty()) {

        cout << "Queue is Empty";

        return INT_MIN;

    }

    return queue[front];

}

int dequeue() { // remove front and return it

    if (isEmpty()) {

        cout << "Queue is Empty!";

        return INT_MIN;

    }

    return queue[front++];

}


int main() {

    enqueue(1);

    enqueue(2);

    enqueue(3);

    enqueue(4);

    enqueue(5);

    enqueue(6);

    enqueue(7);

    enqueue(8);

    enqueue(9);

    enqueue(10);

    enqueue(11);

    // endl stand for end line

    cout << endl;

    cout << dequeue() << endl;

    cout << dequeue() << endl;

    cout << peek() << endl;

    cout << len() << endl;

}




____E-R Diagram____


CREATE TABLE `Categories` (

  `category_ID` int(50),

  `category_name` varchar(250),

  `category_type` varchar(250),

  PRIMARY KEY (`category_ID`)

);


CREATE TABLE `Product` (

  `product_ID` int(50),

  `category_ID` int(50),

  `product_name` varchar(250),

  PRIMARY KEY (`product_ID`)

);


CREATE TABLE `Customer` (

  `customer_ID` int(50),

  `name` varchar(250),

  `number` int(50),

  `address` varchar(250),

  PRIMARY KEY (`customer_ID`)

);


CREATE TABLE `Shopping Order` (

  `order_ID` int(50),

  `customer_ID` int(50),

  `date` int(50),

  PRIMARY KEY (`order_ID`)

);


CREATE TABLE `Payment` (

  `payment_ID` int(50),

  `category_ID` int(50),

  `method` varchar(50),

  PRIMARY KEY (`payment_ID`)

);