






السمعة:
- إنضم17 يونيو 2023
- المشاركات 515
- الحلول 10
- مستوى التفاعل 1,106
- النقاط 93
علماً أني لست مَن قام بعمل المشروع 3b0~0d
هدية لأعضاء شبكة شل
رسالة الشباب
السلام عليكم ورحمة الله ، يعطيكم العافية جميعًا .هدية لأعضاء شبكة شل

رسالة الشباب
عملنا بروجيكت كامل بخص مادة ( تراكيب البيانات ) بالبداية احنا 4 طلاب ،
• معتصم أبو بهاء
• أوس السلامات
• محمد جودات
• أنس الشمالي
والمشروع بتضمن بداية المادة لنهايتها بتقدروا تشوفوه وتجربوه ، وأي حد عنده أي استفسار بخصوص أي شغلة يتواصل معي وبوصلو للشباب وبنشرحله اياها إن شاء الله. هسا البرنامج في قوائم ، لا تكبس Enter بأي شيء بتدخله ، أنت مجرد ما تحط الرقم اللي بدك اياه لحاله بدخلك عالمواضيع ، يعني كبسة Enter شيلها من بالك , لأن استخدمنا مكتبة <conio.h> فبتسهل استخدام القوائم .
والبرنامج بتضمن كمان آلة حاسبة بتحول من Infix To Postfix على مبدأ الـ Stack . والبرنامج لازم يتشغل على الـ Visual studio أو أي كومبايلر بس مش أونلاين .
قبل ما أنهي حاب أنوّه على شغلة يخوان رجاءً عشان الحلال والحرام وما يصير مشاكل ، إذا بدك تشارك الكود مع أي حدا لا تعدل عليه كأنه أنت اللي كتبته أو تحكي أنه باسمك أو أو ، أحسن النا والك ، عشان تعبنا ما يروح هيك , وشكرًا على تفهمكم والسلام عليكم
هذا هو ملف الكود
أو هذا هو الكود
أو هذا هو الكود

C++:
#include <iostream>
#include <conio.h>
#include <Windows.h>
#ifdef _WIN32
#include <windows.h> // For Windows system("cls")
#else
#include <cstdlib> // For Linux/Mac system("clear")
#endif
#include <iomanip>
using namespace std;
class node
{
public:
int data;
node* prev, * next;
node() { prev = next = NULL; data = 0; }
};
class Single_Linkedlist
{
int counter; // To Count The Nodes
node* head, * tail;
public:
Single_Linkedlist() { counter = 0; head = tail = NULL; }
bool IsEmpty() // Check Whether The Linked List Is Empty OR Not
{
return head == NULL;
}
// Function IsFound => To Check Whether the element is found or not
int IsFound(int value)
{
bool found = false; // Initial Value = false
int count = 0;
node* temp = head;
while (temp != NULL)
{
if (temp->data == value)
{
++count;
}
temp = temp->next;
}
return count;
}
// Function To Display The Linked List
void Display()
{
node* temp = head;
while (temp != NULL)
{
cout << " " << temp->data << " |";
temp = temp->next;
}
cout << endl;
}
void InsertFirst_Single(int newvalue) // Inserting To The Position 1
{
// create a newnode & give value to the newvalue
node* newnode = new node;
newnode->data = newvalue;
newnode->next = NULL;
if (IsEmpty())
{
head = tail = newnode;
}
else
{
newnode->next = head;
head = newnode;
}
++counter;
}
// Function To Add Node at last position
void Append_Single(int newvalue)
{
node* newnode = new node;
newnode->data = newvalue;
newnode->next = NULL;
if (IsEmpty())
{
head = tail = newnode;
}
else
{
tail->next = newnode;
tail = newnode;
}
++counter;
}
// Function To Insert as Particular Position
void Inserting_Single(int index, int newvalue)
{
node* newnode = new node;
newnode->data = newvalue;
if (index < 0 or index > counter + 1)
{
cout << "Error, Invalid Index, Please Try Again ..\n";
return;
}
else if (index == 1)
{
InsertFirst_Single(newvalue);
}
else if (index == counter + 1)
{
Append_Single(newvalue);
}
else
{
int i = 1;
node* temp = head;
while (i != index - 1)
{
temp = temp->next;
++i;
}
newnode->next = temp->next;
temp->next = newnode;
++counter;
}
}
// Delete Nodes //
void DeleteNode(int Value)
{
node* current = head;
node* Before = current;
if (IsEmpty())
{
cout << "\n Linked List Is Empty ,Insert Elements .";
}
else
{
while (current->data != Value)
{
Before = current;
current = current->next;
if (current == NULL)
break;
}
if (current == NULL)
cout << "\nDidn't Find The Value You Entered To Delete.\n";
else
{
if (head->data == Value)
{
head = head->next;
}
Before->next = current->next;
cout << "\nDelete For " << current->data << " Completed.\n";
delete current;
--counter;
}
}
}
void Delete(int value)
{
if (IsEmpty())
{
cout << "The Linked list is empty, no item to delete.\n";
return;
}
else
{
if (IsFound(value) == 1)
DeleteNode(value);
else if (IsFound(value) > 1)
{
Display();
cout << "\nThe Value You Want To Delete Found Multiple Times In Linked List.\n"
<< "\nEnter The Location You Want To Delete It By Occurence :\n"
<< "\n [1] First\n [2] Middle\n [3] Last\n [4] Number_Of_Repetition\n [5] All Of Them\n"
<< " - Enter Option : "; char op = _getch();
if (op == '1')
{
DeleteNode(value);
}
else if (op == '2' || op == '3')
{
node* current = head, * prev = current;
int pos = 0;
if (op == '2')
{
if (IsFound(value) % 2 == 0)
pos = IsFound(value) / 2;
else
pos = IsFound(value) / 2 + 1;
}
else
pos = IsFound(value);
while (current->data != value || pos > 1)//
{
prev = current;
current = current->next;
if (current->data == value)
--pos;
}
if (current == head)
{
head = head->next;
}
prev->next = current->next;
cout << "\nDelete For " << current->data << " Completed.\n";
delete current;
--counter;
}
else if (op == '4')
{
int pos = 0;
cout << "\nEnter The Position Based On The Repetition Of The Value : "; cin >> pos;
if (pos < 0)pos *= -1;
if (pos > 0 && pos <= IsFound(value))
{
node* current = head, * prev = current;
if (!(pos == 1 && head->data == value))
{
while (current->data != value || pos != 0)
{
prev = current;
current = current->next;
if (current->data == value)
--pos;
}
}
else
{
head = head->next;
}
prev->next = current->next;
cout << "\nDelete For " << current->data << " Completed.\n";
delete current;
--counter;
}
else
{
cout << "\nThere Is No Repetition " << pos << " For The Value You Entered To Delete.";
}
}
else if (op == '5')
{
cout << "\n - Deleting All Values In Linked List.\n";
int pos = IsFound(value);
while (pos)
{
DeleteNode(value);
--pos;
}
}
}
else
{
cout << "\nThe Value You Entered To Delete Is Not Found.\n\n";
}
}
}
////////////////
int count()
{
return counter;
}
// Function To Update Nodes Value
void Update(int old_value)
{
if (IsEmpty())
{
cout << "The Linked List Is Empty, No Node To Update ..\n";
return;
}
else
{
if (IsFound(old_value))
{
node* temp = head;
while (temp->data != old_value)
{
temp = temp->next;
}
cout << "Enter New Value : ";
cin >> old_value;
temp->data = old_value;
}
else
{
return;
}
}
}
// Function To Search Nodes
void Search(int key)
{
bool found = false; int i = 1;
node* temp = head;
while (temp != NULL)
{
if (temp->data == key)
{
found = true;
cout << " Position " << i << " .\n";
}
temp = temp->next;
++i;
}
if (found)
return;
else
cout << "Error, Not Found" << endl;
}
void DestroyList() {
node* current = head;
node* next;
while (current != nullptr) {
next = current->next;
delete current;
current = next;
}
head = tail = nullptr;
counter = 0;
}
};
// #################################################
class Simple_Queue_As_Array
{
public:
#define size 5
int queue[5];
int front = -1, rear = -1;
bool isEmpty()// to check if the queue is empty or not
{
return(rear == -1 && front == -1 || front == (size));// if the value of the front is 4 that mean i have delete all vlaues
}
bool isFull()
{
return(front == 0 && rear == (size - 1));
}
void enqueue(int value)
{
if (isEmpty())
{
front = rear = 0;
queue[rear] = value;
}
else if (!isFull())
{
if (front == size)
{
front = rear = -1;
}
else {
queue[++rear] = value;
}
}
else
{
cout << "The queue is full you can add just 5 element !!" << endl;
}
}
int dequeue()
{
int valueOf = 0;
if (!isEmpty())
{
valueOf = queue[front];
queue[front] = 0;
front++;
return valueOf;
}
else {
cout << "The queue is empty !!" << endl;
return valueOf;
}
}
void print()
{
if (isEmpty())
{
cout << "The queue is empty !!" << endl;
}
else
{
for (int i = front; i <= rear; i++)
{
cout << "the value is [ " << queue[i] << " ]" << endl;
}
}
}
int get_front()
{
return queue[front];
}
int get_rear()
{
return queue[rear];
}
bool isFound(int SearchVal) {
for (int i = front; i <= rear; i++)
{
if (queue[i] == SearchVal)
{
return true;
}
}
return false;
}
void Clear()
{
if (isEmpty())
{
cout << "The Queue Is Empty, No Item To Delete \n";
return;
}
else
{
for (int i = 0; i < size; i++)
{
dequeue();
}
}
}
};
class Queue_As_Linked_List
{
public:
node* front, * rear;
int count_node = 0;
Queue_As_Linked_List()
{
front = rear = NULL;
}
bool isEmpty()
{
return(rear == NULL && front == NULL);
}
void enqueue(int value)
{
node* NewNode = new node();
NewNode->data = value;
if (isEmpty())
{
front = rear = NewNode;
}
else
{
rear->next = NewNode;
rear = NewNode;
}
++count_node;
}
int dequeue()
{
node* del;
int value;
if (isEmpty())
{
return 0;
}
else if (front == rear)
{
--count_node;
del = front;
value = front->data;
delete del;
front = rear = NULL;
return value;
}
else
{
--count_node;
del = front;
value = front->data;
front = front->next;
delete del;
return value;
}
}
void clear()
{
if (isEmpty())
{
cout << "The queue is empty !!!!" << endl;
}
else
{
while (front != NULL)
{
dequeue();
}
}
}
int count()
{
return count_node;
}
int get_front()
{
return front->data;
}
int get_rear()
{
return rear->data;
}
bool isFound(int value)
{
if (isEmpty())
{
cout << "The queue is empty !!!!" << endl;
return false;
}
else
{
node* temp = front;
while (temp != NULL)
{
if (value == temp->data)
{
cout << "Your value found " << endl;
return true;
}
temp = temp->next;
}
cout << "Your value not found " << endl;
return false;
}
}
void print()
{
int count_print = 0;
if (isEmpty())
{
cout << "The queue is empty !!!!" << endl;
}
else
{
node* temp = front;
while (temp != NULL)
{
++count_print;
cout << "[ " << count_print << " ] -------> " << temp->data << endl;
temp = temp->next;
}
}
}
};
class circular_as_arrary
{
public:
int* queue_c;
int size2;
circular_as_arrary() :size2(0), queue_c(NULL) {}
void sizee(int& s)
{
size2 = s;
}
int front = -1, rear = -1;
int count_print = 0;
bool isEmpty()
{
if (rear == -1 && front == -1)
{
return true;
}
else
{
return false;
}
}
bool isFull()
{
if (rear == size2 - 1 && front == 0)
{
return true;
}
else if (rear == front - 1)
{
return true;
}
else
{
return false;
}
}
void enqueue_c(int value)
{
if (isFull())
{
cout << "The queue_c is full you can add just 5 element !!" << endl;
}
else
{
if (isEmpty())
{
++count_print;
front = rear = 0;
queue_c[rear] = value;
}
else if (rear == size2 - 1)
{
++count_print;
rear = 0;
queue_c[rear] = value;
}
else
{
++count_print;
rear++;
queue_c[rear] = value;
}
}
}
void dequeue_c()
{
if (!isEmpty())
{
if (front <= rear)
{
--count_print;
queue_c[front] = 0;
front++;
}
else if (front == size2 - 1)
{
--count_print;
queue_c[front] = 0;
front = 0;
}
else
{
--count_print;
queue_c[front] = 0;
front++;
}
}
else
{
return;
}
}
void print()
{
int count_print_Print = 0;
if (isEmpty())
{
cout << "The queue_c is empty" << endl;
}
else
{
if (front <= rear)
{
for (int i = front; i <= rear; i++)
{
++count_print_Print;
cout << "[" << count_print_Print << "] the value is : " <<
queue_c[i] << endl;
}
}
else
{
for (int i = front; i < size2; i++)
{
++count_print_Print;
cout << "[" << count_print_Print << "] the value is : " <<
queue_c[i] << endl;
}
for (int i = 0; i <= rear; i++)
{
++count_print_Print;
cout << "[" << ++count_print_Print << "] the value is : " <<
queue_c[i] << endl;
}
}
}
}
int Get_Front() { return queue_c[front]; }
int Get_Rear() { return queue_c[rear]; }
bool isFound(int value)
{
bool flag = false;
if (isEmpty())
{
cout << "The queue_c is empty" << endl;
}
else
{
if (front <= rear)
{
for (int i = front; i <= rear; i++)
{
if (queue_c[i] == value)
{
return !flag;
}
}
}
else
{
for (int i = front; i < size2; i++)
{
if (queue_c[i] == value)
{
return !flag;
}
}
for (int i = 0; i <= rear; i++)
{
if (queue_c[i] == value)
{
return !flag;
}
}
}
}
return flag;
}
void clear_c()
{
if (isEmpty())
{
cout << "The Queue Is Empty, No Item To Delete \n";
return;
}
else
{
for (int i = 0; i < size2; i++)
{
dequeue_c();
}
}
}
};
class Doubly_LinkedList
{
private:
int counter;
node* head, * tail;
public:
Doubly_LinkedList() { counter = 0; head = tail = NULL; }
bool IsEmpty()
{
return head == NULL;
}
int getCounter() { return counter; }
void InsertFirst(int newvalue)
{
node* newnode = new node;
newnode->data = newvalue;
newnode->next = NULL;
newnode->prev = NULL;
if (IsEmpty())
{
head = tail = newnode;
}
else
{
newnode->next = head;
head->prev = newnode;
head = newnode;
}
++counter;
}
void Append(int newvalue)
{
node* newnode = new node;
newnode->data = newvalue;
newnode->next = NULL;
newnode->prev = NULL;
if (IsEmpty())
{
head = tail = newnode;
}
else
{
newnode->prev = tail;
tail->next = newnode;
tail = newnode;
}
counter++;
}
void Display()
{
node* temp = head;
while (temp != NULL)
{
cout << " " << temp->data << " |";
temp = temp->next;
}
cout << endl;
}
void Display_Reverse()
{
node* temp = tail;
while (temp != NULL)
{
cout << " " << temp->data << " |";
temp = temp->prev;
}
cout << endl;
}
void Inserting(int index, int newvalue)
{
if (index < 1 or index > counter + 1)
{
cout << "Invalid Index\n";
return;
}
else
{
node* newnode = new node;
newnode->data = newvalue;
newnode->next = NULL;
newnode->prev = NULL;
if (index == 1)
{
InsertFirst(newvalue);
}
else if (index == counter + 1)
{
Append(newvalue);
}
else
{
int i = 1;
node* temp = head;
while (i != index - 1)
{
temp = temp->next;
++i;
}
newnode->next = temp->next;
newnode->prev = temp;
temp->next->prev = newnode;
temp->next = newnode;
++counter;
}
}
}
void UpdateValue(int oldValue)
{
if (IsFound(oldValue))
{
node* current = head;
while (current->data != oldValue)
current = current->next;
int newValue;
cout << "\nEnter The New Value For { " << current->data << " } : ";
cin >> newValue;
current->data = newValue;
}
else
cout << "\nThe Value You Want To Update Is Not Found.\n";
}
bool IsFound(int key)
{
bool found = false;
node* temp = head;
while (temp != NULL)
{
if (temp->data == key) {
found = true;
break;
}
temp = temp->next;
}
return found;
}
void Delete(int key) {
if (IsEmpty()) {
cout << "The Linked list is empty, no item to delete.\n";
return;
}
else {
int count = CountOccurrences(key);
if (count > 0) {
if (count > 1) {
cout << "\nThe Linked list contains duplicated data. Choose an option:\n";
cout << "[1] Delete First Duplicated Item\n";
cout << "[2] Delete Last Duplicated Item\n";
cout << "[3] Delete All Duplicated Items\n";
cout << "[4] Delete a Duplicated Item at a Particular Index\n";
char choice = _getch();
if (choice == '1')
{
DeleteFirstDuplicate(key);
}
else if (choice == '2')
{
DeleteLastDuplicate(key);
}
else if (choice == '3')
{
DeleteAllDuplicates(key);
}
else if (choice == '4')
{
DeleteDuplicateAtPosition(key);
}
else
{
cout << "Invalid input, please enter a valid option.\n";
return;
}
}
else {
DeleteSingleOccurrence(key);
}
}
else {
cout << "The Value You Entered To Delete Is Not Found.\n";
}
}
Display();
}
int CountOccurrences(int key) {
int count = 0;
node* current = head;
while (current != nullptr) {
if (current->data == key) {
count++;
}
current = current->next;
}
return count;
}
void DeleteSingleOccurrence(int key) {
node* current = head;
node* prev = nullptr;
while (current != nullptr) {
if (current->data == key) {
if (prev == nullptr) {
head = current->next;
delete current;
return;
}
else {
prev->next = current->next;
delete current;
return;
}
}
prev = current;
current = current->next;
}
}
void DeleteFirstDuplicate(int key) {
node* current = head;
node* prev = nullptr;
while (current != nullptr) {
if (current->data == key) {
if (prev == nullptr) {
head = current->next;
delete current;
return;
}
else {
prev->next = current->next;
delete current;
return;
}
}
prev = current;
current = current->next;
}
}
void DeleteLastDuplicate(int key) {
node* current = head;
node* lastOccurrence = nullptr;
while (current != nullptr) {
if (current->data == key) {
lastOccurrence = current;
}
current = current->next;
}
if (lastOccurrence != nullptr) {
node* temp = head;
node* prev = nullptr;
while (temp != lastOccurrence) {
prev = temp;
temp = temp->next;
}
if (prev == nullptr) {
head = lastOccurrence->next;
delete lastOccurrence;
}
else {
prev->next = lastOccurrence->next;
delete lastOccurrence;
}
}
}
void DeleteAllDuplicates(int key)
{
node* current = head;
node* prev = nullptr;
while (current != nullptr) {
if (current->data == key) {
if (prev == nullptr) {
head = current->next;
delete current;
current = head;
}
else {
prev->next = current->next;
delete current;
current = prev->next;
}
}
else {
prev = current;
current = current->next;
}
}
}
void DeleteDuplicateAtPosition(int key) {
int position;
cout << "Enter the position of the duplicate item to delete: ";
cin >> position;
while (cin.fail() || position <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter the position of the duplicate item to delete: ";
cin >> position;
}
if (position <= 0) {
cout << "Invalid position. Please Enter a Positive position.\n";
return;
}
node* current = head;
node* prev = nullptr;
int count = 0;
while (current != nullptr) {
if (current->data == key) {
count++;
if (count == position) {
if (prev == nullptr) {
head = current->next;
delete current;
}
else {
prev->next = current->next;
delete current;
}
return;
}
}
prev = current;
current = current->next;
}
cout << "Invalid position. The duplicate item at the specified position was not found.\n";
}
void DestroyList() {
node* current = head;
node* next;
while (current != nullptr) {
next = current->next;
delete current;
current = next;
}
head = tail = nullptr;
counter = 0;
}
};
class Stack_j
{
node* Top;
public:
Stack_j()
{
Top = nullptr;
}
bool isempty()
{
return Top == NULL;
}
void Push(int value)
{
node* newnode = new node();
newnode->data = value;
if (isempty())
{
Top = newnode;
}
else
{
newnode->next = Top;
Top = newnode;
}
}
void Pop()
{
if (isempty())
{
cout << "This stack is full \n";
}
else
{
cout << "Deleted this value " << Top->data << endl;
node* delptr = Top;
Top = Top->next;
delete delptr;
}
}
int Peek()
{
return Top->data;
}
void Display()
{
node* Temp = Top;
while (Temp != NULL)
{
cout << " " << Temp->data << " |";
Temp = Temp->next;
}
cout << endl << endl;
}
void IsFull()
{
node* test = new node();
if (test == NULL)
{
cout << " Stack Is Full \n";
}
else
{
cout << " Stack Is Not Full \n";
}
}
void Found(int value)
{
node* Temp = Top;
while (Temp != NULL)
{
if (Temp->data == value)
{
cout << " The Value " << value << " Is Found \n";
return;
}
else {
Temp = Temp->next;
}
}
cout << " This value " << value << " not found \n";
}
void Count()
{
if (isempty())
{
cout << "The Stack Is Empty \n";
}
else {
int counter = 0;
node* Temp = Top;
while (Temp != NULL)
{
counter++;
Temp = Temp->next;
}
cout << "[+] The Number OF Node is " << counter << endl;
}
}
};
template<class type>
struct mathNode
{
public:
type data;
mathNode* link;
};
template<class type>
class mathStack
{
mathNode<type>* Top;
int size1;
public:
mathStack() :Top(NULL), size1(0) {}
bool IsEmpty()
{
return Top == NULL;
}
int GetSize() { return size1; }
void Push(type value)
{
mathNode<type>* newNode = new mathNode<type>;
newNode->data = value;
newNode->link = NULL;
if (Top == NULL)
{
Top = newNode;
}
else
{
newNode->link = Top;
Top = newNode;
}
++size1;
}
type Pop()
{
if (IsEmpty())
{
cout << "\nStack Empty."; return 0;
}
else
{
type revalue = Top->data;
mathNode<type>* temp = Top;
Top = Top->link;
delete temp;
--size1;
return revalue;
}
}
type GetTop()
{
if (IsEmpty())
return 0;
else
return Top->data;
}
// Distructer .
~mathStack()
{
while (Top != NULL)
Pop();
}
};
void math_Operations()
{
cout << "\n - Integer Numbers Only ..."
<< "\n - Valid Operations [ + , - , * , / , ( ) ] && Negative Numbers."
<< "\n -> Example : 50*3-5/2*(-5*2)\n\n";
mathStack<char> string_stack;
string infix = "", Postfix = "";
///////
cout << " # You\'r Equation : "; cin >> infix;
//////
int i = 0;
int num_Of_Numbers = 1;// For numContainter Size;
/* Determine The Number Of Numbers In The Infix String...
& Check Some Inputs In The Equation :*/
bool enterConverting = true;
short int openedB = 0, closedB = 0;
while (i < infix.length())
{
if (infix[i] == '*' || infix[i] == '/' || infix[i] == '+' || infix[i] == '-')
{
++num_Of_Numbers;
}
else if ((infix[i] >= 'A' && infix[i] <= 'Z') || (infix[i] >= 'a' && infix[i] <= 'z'))
{
enterConverting = false;
cout << "\n - Invalid Equation\n\tYou Entered A Character.. [ " << infix[i] << " ]\n\n";
break;
}
else if (!(infix[i] >= '0' && infix[i] <= '9') && (infix[i] != '(' && infix[i] != ')'))
{
enterConverting = false;
cout << "\n - Invalid Equation\n\tInvalid Input [ " << infix[i] << " ]\n\n";
break;
}
///
if (infix[i] == '(')
++openedB;
else if (infix[i] == ')')
++closedB;
if (openedB != closedB && (i + 1) == infix.length())
{
cout << "\n - Invalid Equation\n\t Wrong Parantheses ( ) Input\n\n";
enterConverting = false;
}
++i;
}
if (enterConverting)
{
// For The Digits Of Each Number :
int* lengthContainer = new int[num_Of_Numbers + 1];
lengthContainer[0] = NULL;
int numlength = 0, index = 0;
///////
// Scanning The String Infix Form To Convert It To Postfix Form ;
i = 0; bool negative = false, enterEvaluation = true;
while (i < infix.length())
{
if (infix[i] >= '0' && infix[i] <= '9')
{
Postfix += infix[i];
++numlength;
}
else
{
if ((infix[i] != '-' && infix[i] != '(') && i == 0) // Check Equation.
{
cout << " - Invalid Equation \n\t [ + , - , * , ) ] First Of The Equation .\n\n";
enterEvaluation = false;
break;
}
if ((infix[i + 1] > ')' && infix[i + 1] <= '/') && (infix[i] != 44 && infix[i] != 46) && infix[i + 1] != '-' && infix[i] != ')') // Check Equation.
{
if (infix[i] == '(')
cout << "\n - Invalid Equation\n\tYou Should Not Enter An Operation After \"(\" Bracket Directly.\n\n";
else
cout << "\n - Invalid Equation\n\tTwo Operators Beside Each Other ..." << infix[i] << infix[i + 1] << "\n\n";
enterEvaluation = false;
break;
}
if (infix[i] == '*' || infix[i] == '/' || infix[i] == '+' || infix[i] == '-') // Giving lengthContainer Array The Length Of The Number Before Any Operation.
{
if (infix[i] == '-' && i == 0)
// If The First Element Is '-' , That Means The First Number Is Negative Number .
{
Postfix += '0';
++numlength;
negative = true;
}
lengthContainer[index] = numlength;
numlength = 0;
++index;
}
/////////////////////
if ((infix[i] >= '(' && infix[i] <= '/') && (infix[i] != 44 && infix[i] != 46) && !negative) // Operators In ASCII Code.
// ASCII 44 = , & 46 = .
// We Want The Operations Done Only On The Main Math Operators [ ( ) , * , + , - , / ] .
{
if (infix[i] == '*' || infix[i] == '/')
{
if (string_stack.GetTop() == '/' || string_stack.GetTop() == '*') // IF the operator in the stack is '*' OR '/' We have to pop it from the stack to push the coming operator (*)
{
Postfix += string_stack.Pop();
string_stack.Push(infix[i]);
}
else // which means that the operator in the stack is '+' OR '-' OR '(' So We will push '*' OR '/' directly.[Precedence Rules]
string_stack.Push(infix[i]);
}
else if (infix[i] == '+' || infix[i] == '-')
{
/*
We Are Comparing First, if the operator in the top of stack is '*' OR '/' , we are going to pop it out,
then we are look again , if there is any '+' OR '-' After the poped operator , we are going to pop it too before pushing the coming operator,
because the rule sayed , if the operator equal the pushed operator in the precedence we have to pop it before pushing it into the STACK .
*/
if (string_stack.GetTop() == '/' || string_stack.GetTop() == '*')
{
Postfix += string_stack.Pop();
if (string_stack.GetTop() == '+' || string_stack.GetTop() == '-')
Postfix += string_stack.Pop();
string_stack.Push(infix[i]);
}
/* IF The Operator In The Stack Was Not '*' OR '/' It Must Be '+' OR '-' So This else if statement dealing with this .*/
else if (string_stack.GetTop() == '+' || string_stack.GetTop() == '-')
{
Postfix += string_stack.Pop();
string_stack.Push(infix[i]);
}
else// if the Top was '('
string_stack.Push(infix[i]);
}
else // Open & Closed Brackets ( ) Case :
{
if (infix[i] == '(')
{
if (i != 0 && (infix[i - 1] >= '0' && infix[i - 1] <= '9')) // Check Equation.
{
cout << "\n - Invalid Equation\n\tYou Should Input The Operation You Want Before Opened Bracket \"(\" ... " << infix[i - 1] << infix[i] << " Error.\n\n";
enterEvaluation = false;
break;
}
string_stack.Push(infix[i]);
}
else if (infix[i] == ')')
{
if (infix[i - 1] < '0' && infix[i - 1] != ')') // Check Equation.
{
if (infix[i - 1] == '(')
cout << "\n - Invalid Equation\n\tEmpty Parentheses \"( )\"\n\n";
else
cout << "\n - Invalid Equation\n\tThere Is An Operation Before Closed Breaket \")\" ..." << infix[i - 1] << infix[i] << "\n\n";
enterEvaluation = false;
break;
}
while (string_stack.GetTop() != '(')
Postfix += string_stack.Pop();
string_stack.Pop(); // Pop '(' From The Stack.
}
}
if (infix[i + 1] == '-' && infix[i] != ')') // Check If There Is Negative Number Next Of Operation 5*-7 OR 5*(-7)
{
Postfix += "0";
negative = true;
lengthContainer[index] = 1;// 1 digit Of Zero For The Negative Number. 063- => -63
++index;
++i;// Skipping '-' Operator OF The Negative Number.
}
}
}
++i;
if (negative == true && !(infix[i] >= '0' && infix[i] <= '9'))// For The Negative In First/Middle/Last Of Equation
{
Postfix += '-';
negative = false;
}
if (i == infix.length())
{
lengthContainer[index] = numlength;
numlength = 0;
}
}
// EVALUATION PROCESS :
if (enterEvaluation)
{
//After The Loop And Converting Infix To PostFix We Want To Check If Stack Have Any Operators To Appened :
while (string_stack.GetSize() != 0)
Postfix += string_stack.Pop();
cout << "\n # PostFix Form : " << Postfix;
mathStack<double> evaluation;
string Number = "";
i = 0;
index = 0;
double result = 0;
while (i < Postfix.length())
{
if (Postfix[i] >= '0' && Postfix[i] <= '9')
{
Number += Postfix[i];
if (Number.length() == lengthContainer[index])
{
double realNum = 0;
int l = 0;
while (l < Number.length())
{
realNum = realNum * 10 + int(Number[l]) - 48;
++l;
}
Number = "";
evaluation.Push(realNum);
++index;
}
}
else
{
double firstNumber = 0, secondNumber = 0;
secondNumber = evaluation.Pop();
firstNumber = evaluation.Pop();
switch (Postfix[i])
{
case '+':
evaluation.Push(firstNumber + secondNumber);
break;
case '-':
evaluation.Push(firstNumber - secondNumber);
break;
case '*':
evaluation.Push(firstNumber * secondNumber);
break;
case '/':
evaluation.Push(firstNumber / secondNumber);
break;
default:
break;
}
}
++i;
}
result = evaluation.Pop();
cout << "\n\n # Evaluation : " << result << "\n\n";
}
delete[] lengthContainer;
}
}
void centerText(const string& text) {
int consoleWidth;
#ifdef _WIN32
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi);
consoleWidth = csbi.srWindow.Right - csbi.srWindow.Left + 1;
#else
struct winsize size;
ioctl(fileno(stdout), TIOCGWINSZ, &size);
consoleWidth = size.ws_col;
#endif
int leftIndent = int((consoleWidth - text.length()) / 2);
cout << setw(leftIndent) << "" << text << endl;
}
void bubbleSort(int arr[], int size_arr);
void mergeSort(int arr[], int left, int right);
void merge(int arr[], int left, int mid, int right);
void selectionSort(int arr[], int size_arr);
void insertionSort(int arr[], int size_arr);
void quickSort(int arr[], int low, int high);
int partition(int arr[], int low, int high);
int main()
{
centerText("*********************************************");
centerText("* Welcome To Our Program, This Program *");
centerText("* Contains All Subjects Of Data Structure *");
centerText("* The Program Made By: *");
centerText("* - Mo'tasem Abu Baha'a *");
centerText("* - Aws Alslamat *");
centerText("* - Anas Al-Shamaly *");
centerText("* - Mohammad Jawdat *");
centerText("*********************************************");
cout << "\n\n\n\nPress any key to continue...";
cin.get();
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
while (true)
{
cout << "[1] To Use Linked List " << endl;
cout << "[2] To Use Stack " << endl;
cout << "[3] To Use Queue " << endl;
cout << "[4] To Use Sorting " << endl;
cout << "[5] To Use Calculater (Infix To PostFix) " << endl;
cout << "[0] To Exit Program " << endl;
char ch = _getch();
system("cls");
if (ch == '1')
{
while (true)
{
cout << "[+] [1] For Single Linked List " << endl;
cout << "[+] [2] For Doubly Linked List " << endl;
cout << "[+] [0] To Back Main Menu " << endl;
char option = _getch();
if (option == '1')
{
Single_Linkedlist lst;
int size_menu;
int val;
int index;
int search_value;
system("cls");
while (true)
{
cout << "[1] Insert Node At First " << endl;
cout << "[2] Insert Node At Last " << endl;
cout << "[3] Insert Node At Position " << endl;
cout << "[4] Search Item " << endl;
cout << "[5] Updata Value " << endl;
cout << "[6] Show Number Of Element In The Linked List { Counter } " << endl;
cout << "[7] Delete Node In Linked List " << endl;
cout << "[8] Display Linked List " << endl;
cout << "[9] Destoroy The Linked List " << endl;
cout << "[0] Return To The Back Menu " << endl;
char input = _getch();
if (input == '1')
{
system("cls");
cout << "How Many Node You Want To Insert ? : ";
cin >> size_menu;
while (cin.fail() || size_menu <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "How Many Node You Want To Insert ? : ";
cin >> size_menu;
}
for (int i = 1; i <= size_menu; i++)
{
cout << "Enter Value To Insert In [ " << lst.count() + 1 << " ] : ";
cin >> val;
while (cin.fail() || val <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Value To Insert In [ " << lst.count() + 1 << " ] : ";
cin >> val;
}
lst.InsertFirst_Single(val);
}
system("cls");
}
else if (input == '2')
{
system("cls");
cout << "How Many Node You Want To Insert ? : ";
cin >> size_menu;
while (cin.fail() || size_menu <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "How Many Node You Want To Insert ? : ";
cin >> size_menu;
}
for (int i = 1; i <= size_menu; i++)
{
cout << "Enter Value To Insert In [ " << lst.count() + 1 << " ] : ";
cin >> val;
while (cin.fail() || val <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Value To Insert In [ " << lst.count() + 1 << " ] : ";
cin >> val;
}
lst.Append_Single(val);
}
system("cls");
}
else if (input == '3')
{
system("cls");
cout << "How Many Node You Want To Insert ? : ";
cin >> size_menu;
while (cin.fail() || size_menu <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "How Many Node You Want To Insert ? : ";
cin >> size_menu;
}
for (int i = 1; i <= size_menu; i++)
{
cout << "The Counter In Linked List Is " << lst.count() << endl << endl << endl;
cout << "Enter The Position You Want To Insert In ";
cin >> index;
while (cin.fail() || index <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Position You Want To Insert In ";
cin >> index;
}
cout << "Enter Value To Insert In [ " << lst.count() + 1 << " ] : ";
cin >> val;
while (cin.fail() || val <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Value To Insert In [ " << lst.count() + 1 << " ] : ";
cin >> val;
}
lst.Inserting_Single(index, val);
}
system("cls");
}
else if (input == '4')
{
system("cls");
if (lst.IsEmpty())
{
system("cls");
cout << "The Linked List Is Empty, You Must Insert At Least One Value \n";
Sleep(2000);
system("cls");
continue;
}
else
{
cout << "Enter The Value You Want To Search It : ";
cin >> search_value;
while (cin.fail() || search_value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Value You Want To Search It : ";
cin >> search_value;
}
if (lst.IsFound(search_value))
cout << "Yes, The Item Is Found \n";
else
cout << "No, The Item Isn't Found\n ";
}
}
else if (input == '5')
{
system("cls");
if (lst.IsEmpty())
{
system("cls");
cout << "The Linked List Is Empty, You Must Insert At Least One Value \n";
Sleep(2000);
system("cls");
continue;
}
else
{
cout << endl << endl;
lst.Display();
cout << endl << endl;
cout << "How Many Node You Want To Update ? : ";
cin >> size_menu;
while (cin.fail() || size_menu <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "How Many Node You Want To Update ? : ";
cin >> size_menu;
}
if (size_menu > lst.count() or size_menu < 0)
{
cout << "Error, The Linked List Contain [ " << lst.count() << " ] Nodes " << endl;
Sleep(1500);
continue;
system("cls");
}
else
{
for (int i = 1; i <= size_menu; i++)
{
cout << "Enter The Old Value You Want To Updata It : ";
cin >> val;
while (cin.fail() || val <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Old Value You Want To Updata It : ";
cin >> val;
}
if (!lst.IsFound(val))
{
cout << "Not Found The Item In The Linked List \n";
Sleep(1500);
system("cls");
continue;
}
else
{
lst.Update(val);
}
system("cls");
cout << "The Linked List After Updata Is : " << endl << endl << endl;
lst.Display();
Sleep(2500);
system("cls");
}
}
}
}
else if (input == '6')
{
system("cls");
cout << "The Number Of Nodes Is : " << lst.count() << endl;
}
else if (input == '7')
{
if (lst.IsEmpty())
{
cout << "The Linked List Is Empyt, No Item To Delete .\n";
Sleep(2000);
system("cls");
continue;
}
else
{
system("cls");
cout << endl << endl;
lst.Display();
cout << endl << endl;
cout << "How Many Node You Want To Delete ? : ";
cin >> size_menu;
while (cin.fail() || size_menu <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Invalid input, please enter a number." << endl;
cin >> size_menu;
}
if (size_menu > lst.count() or size_menu < 0)
{
cout << "Error, The Linked List Contain [ " << lst.count() << " ] " << endl;
Sleep(1500);
continue;
system("cls");
}
else
{
for (int i = 1; i <= size_menu; i++)
{
cout << "Enter The Values You Want To Delete : ";
cin >> val;
while (cin.fail() || val <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Values You Want To Delete : ";
cin >> val;
}
lst.Delete(val);
}
Sleep(1500);
system("cls");
cout << "The Linked List After Delete Is : " << endl << endl << endl;
lst.Display();
Sleep(2500);
system("cls");
}
}
}
else if (input == '8')
{
if (lst.IsEmpty())
{
cout << "The Linked List Is Empty, No Items To Display It .\n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << endl << endl;
lst.Display();
cout << endl << endl;
}
}
else if (input == '9')
{
system("cls");
lst.DestroyList();
cout << "Linked List Destroyed ." << endl;
}
else if (input == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
else if (option == '2')
{
system("cls");
Doubly_LinkedList list;
while (true)
{
cout << "[1] Insert Node At First " << endl;
cout << "[2] Insert Node At Last " << endl;
cout << "[3] Insert Node At Position " << endl;
cout << "[4] Search Item " << endl;
cout << "[5] Updata Value " << endl;
cout << "[6] Show Number Of Element In The Linked List { Counter } " << endl;
cout << "[7] Delete Node In Linked List " << endl;
cout << "[8] Display Linked List " << endl;
cout << "[9] Destoroy The Linked List " << endl;
cout << "[0] Return To The Back Menu " << endl;
option = _getch();
system("CLS");
if (option == '1')
{
cout << "Enter How Many Node You Want To Insert It : ";
int x;
cin >> x;
while (cin.fail() || x <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter How Many Node You Want To Insert It : ";
cin >> x;
}
for (int i = 1; i <= x; i++)
{
system("cls");
int value = 0;
cout << "Enter Value To Insert First In [ " << list.getCounter() + 1 << " ] ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Value To Insert First In [ " << list.getCounter() + 1 << " ] ";
cin >> value;
}
list.InsertFirst(value);
}
}
else if (option == '2')
{
cout << "Enter How Many Node You Want To Insert It : ";
int x;
cin >> x;
while (cin.fail() || x <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter How Many Node You Want To Insert It : ";
cin >> x;
}
for (int i = 1; i <= x; i++)
{
system("cls");
int value;
cout << "Enter Value To Insert Last In [ " << list.getCounter() + 1 << " ] ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Value To Insert Last In [ " << list.getCounter() + 1 << " ] ";
cin >> value;
}
list.Append(value);
}
}
else if (option == '3')
{
system("cls");
int value = 0, pos = 0;
cout << " - Insert Node At Particular Position -\n\n"
<< "Enter Value : ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << " - Insert Node At Particular Position -\n\n"
<< "Enter Value : ";
cin >> value;
}
cout << "Enter Position : ";
cin >> pos;
while (cin.fail() || pos <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Position You Want To Insert In ";
cin >> pos;
}
list.Inserting(pos, value);
}
else if (option == '4')
{
system("cls");
if (list.IsEmpty())
{
cout << "The Linked List Is Empty, No Item To Search . \n";
Sleep(1500);
system("cls");
continue;
}
else
{
int value = 0;
cout << " - Search Element -\n\n"
<< "Enter Value To Search : ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << " - Search Element -\n\n"
<< "Enter Value To Search : ";
cin >> value;
}
if (list.IsFound(value))
cout << " " << value << " Is Found.";
else
cout << " " << value << " Is Not Found.";
}
}
else if (option == '5')
{
system("cls");
if (list.IsEmpty())
{
cout << "The Linked List Is Empty, No Item To Update . \n";
Sleep(1500);
system("cls");
continue;
}
else
{
int value = 0;
cout << " - Update Value -\n";
cout << "\nElements : "; list.Display();
cout << "\n\n Enter Element To Update It : ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "\n\n Enter Element To Update It : ";
cin >> value;
}
list.UpdateValue(value);
}
}
else if (option == '6')
{
system("cls");
if (list.IsEmpty())
{
cout << "The Linked List Is Empty, No Item To Search . \n";
Sleep(1500);
system("cls");
continue;
}
else
cout << "\n Number Of Elements In Linked List : " << list.getCounter();
}
else if (option == '7')
{
system("cls");
if (list.IsEmpty())
{
cout << "The Linked List Is Empty, No Item To Delete . \n";
Sleep(1500);
system("cls");
continue;
}
else
{
int value = 0;
cout << " - Deleting Value -\n\n";
cout << "Elements : "; list.Display();
cout << "Enter Value : ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << " - Deleting Value -\n\n";
cout << "Elements : "; list.Display();
cout << "Enter Value : ";
cin >> value;
}
list.Delete(value);
}
}
else if (option == '8')
{
system("cls");
if (list.IsEmpty())
{
cout << "The Linked List Is Empty, No Item To Display . \n";
Sleep(1500);
system("cls");
continue;
}
else
{
cout << " - Display Elements -\n";
cout << endl << endl;
list.Display();
cout << endl << endl;
}
}
else if (option == '9')
{
system("cls");
list.DestroyList();
cout << "Linked List Destroyed ." << endl;
}
else if (option == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << " - Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
cout << "\n\n";
}
}
else if (option == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
else if (ch == '2')
{
Stack_j s;
system("cls");
while (true)
{
cout << "[1] Push\n";
cout << "[2] Search\n";
cout << "[3] Display\n";
cout << "[4] Check If The Stack Is Full OR Not \n";
cout << "[5] Peek\n";
cout << "[6] Pop \n";
cout << "[7] Count \n";
cout << "[0] return Back Menu \n";
char i = _getch();
if (i == '1')
{
system("cls");
int number;
cout << "Enter The Number Of Nodes You Want To Insert It : ";
cin >> number;
while (cin.fail() || number <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Number Of Nodes You Want To Insert It : ";
cin >> number;
}
for (int i = 1; i <= number; i++)
{
int value;
cout << "Element [" << i << "] : ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Element [" << i << "] : ";
cin >> value;
}
s.Push(value);
}
system("cls");
continue;
}
else if (i == '2')
{
if (s.isempty())
{
cout << "The Stack Is Empty, No Item To Search \n" << endl;
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
int search;
cout << "Enter Value You Want To Search It : ";
cin >> search;
while (cin.fail() || search <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Value You Want To Search It : ";
cin >> search;
}
s.Found(search);
Sleep(3000);
system("cls");
}
}
else if (i == '3')
{
if (s.isempty())
{
cout << "The Stack Is Empty, No Items To Display It ." << endl;
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "\n";
s.Display();
}
}
else if (i == '4')
{
system("cls");
s.IsFull();
}
else if (i == '5')
{
if (s.isempty())
{
cout << "The Stack Is Empty !\n" << endl;
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "The Top Value Is : " << s.Peek() << endl;
}
}
else if (i == '6')
{
if (s.isempty())
{
cout << "The Stack Is Empty !\n" << endl;
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
s.Pop();
}
}
else if (i == '7')
{
system("cls");
s.Count();
}
else if (i == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
else if (ch == '3')
{
system("cls");
while (true)
{
cout << "[1] Simple Queue As Array " << endl;
cout << "[2] Circular Queue As Array " << endl;
cout << "[3] Queue As Linked List " << endl;
cout << "[0] Return Main Menu " << endl;
char opt = _getch();
system("cls");
if (opt == '1')
{
char opt;
Simple_Queue_As_Array qu;
while (true)
{
cout << "[1] ENqueue values " << endl;
cout << "[2] DEqueue values " << endl;
cout << "[3] Get Front" << endl;
cout << "[4] Get Rear " << endl;
cout << "[5] Clear The Whole queue " << endl;
cout << "[6] Searching Value " << endl;
cout << "[7] Print Queue" << endl;
cout << "[0] Return To back Menu" << endl;
opt = _getch();
if (opt == '1')
{
system("cls");
int valu;
for (int i = 0; i < size; i++)
{
cout << "Enter Element [ " << i << " ] To The Queue : ";
cin >> valu;
while (cin.fail() || valu <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Element [ " << i << " ] To The Queue : ";
cin >> valu;
}
qu.enqueue(valu);
}
}
else if (opt == '2')
{
if (qu.isEmpty())
{
cout << "The Queue Is Empty, No Item To Dequeued \n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "Dequeued First Node !\n";
qu.dequeue();
}
}
else if (opt == '3')
{
system("cls");
if (qu.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
cout << "The Front Element In Queue Is : " << qu.get_front() << endl;
}
else if (opt == '4')
{
system("cls");
if (qu.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
cout << "The Last Element In Queue Is : " << qu.get_rear() << endl;
}
else if (opt == '5')
{
if (qu.isEmpty())
{
cout << "The Queue Is Empty, No Item To Clear \n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "Cleared Queue ! \n";
qu.Clear();
}
}
else if (opt == '6')
{
if (qu.isEmpty())
{
cout << "The Queue Is Empty, No Item To Search \n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "Enter Item To Search It In Queue : ";
int se;
cin >> se;
while (cin.fail() || se <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Item To Search It In Queue : ";
cin >> se;
}
if (qu.isFound(se))
cout << "The Item { " << se << " } Is Found" << endl;
else
cout << "The Item { " << se << " } Is Not Found" << endl;
}
}
else if (opt == '7')
{
system("cls");
if (qu.isEmpty())
{
cout << "The Queue Is Empty, No Item To Dequeued \n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << endl << endl;
qu.print();
cout << endl << endl;
}
}
else if (opt == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
else if (opt == '2')
{
circular_as_arrary o1;
int size2 = 0;
while (true)
{
cout << "[1] ENqueue values " << endl;
cout << "[2] DEqueue values " << endl;
cout << "[3] Get Front" << endl;
cout << "[4] Get Rear " << endl;
cout << "[5] Clear The Whole queue " << endl;
cout << "[6] Searching Value " << endl;
cout << "[7] Print Queue" << endl;
cout << "[0] Return To back Menu" << endl;
opt = _getch();
if (opt == '1')
{
//
if (size2 > 0)
{
system("CLS");
cout << "\nYou Have To Dequeue All Elements Before Enqueue Elements Again.\n";
continue;
}
//
for (int i = 0; i < size2; i++)
{
o1.dequeue_c();
}
cout << "Enter The Size You Want To Enqueue : \n";
cin >> size2;
while (cin.fail() || size2 <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Size You Want To Enqueue : \n";
cin >> size2;
}
o1.queue_c = new int[size2];
o1.sizee(size2);
system("cls");
int value;
for (int i = 0; i < size2; i++)
{
cout << "Enter Queue Value :";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Queue Value :";
cin >> value;
}
o1.enqueue_c(value);
}
}
else if (opt == '2')
{
system("cls");
if (o1.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
cout << "Dequeued First Node ! \n";
o1.dequeue_c();
}
}
else if (opt == '3')
{
system("cls");
if (o1.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
cout << "The Front Element In Queue Is : " << o1.Get_Front() << endl;
}
else if (opt == '4')
{
if (o1.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "The Rear Element In Queue Is : " << o1.Get_Rear() << endl;
}
}
else if (opt == '5')
{
system("cls");
if (o1.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
cout << "Cleared Queued ! \n";
o1.clear_c();
}
}
else if (opt == '6')
{
system("cls");
if (o1.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
cout << "Enter Item To Search It In Queue : ";
int se;
cin >> se;
while (cin.fail() || se <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Item To Search It In Queue : ";
cin >> se;
}
if (o1.isFound(se))
cout << "The Item { " << se << " } Is Found" << endl;
else
cout << "The Item { " << se << " } Is Not Found" << endl;
}
}
else if (opt == '7')
{
system("cls");
if (o1.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
cout << endl << endl;
o1.print();
cout << endl << endl;
}
}
else if (opt == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
else if (opt == '3')
{
Queue_As_Linked_List q;
Stack_j s;
system("cls");
while (true)
{
cout << "[1] ENqueu\n";
cout << "[2] DEqueue\n";
cout << "[3] Display\n";
cout << "[4] Get_Rear \n";
cout << "[5] Get_Front \n";
cout << "[6] Clear\n";
cout << "[7] Count \n";
cout << "[8] Search \n";
cout << "[0] Return Back Menu \n";
char i = _getch();
if (i == '1')
{
system("cls");
int number;
cout << "Enter The Number Of Nodes You Want To Insert It : ";
cin >> number;
while (cin.fail() || number <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Number Of Nodes You Want To Insert It : ";
cin >> number;
}
for (int i = 1; i <= number; i++)
{
int value = 0;
cout << "Element [" << i << "] : ";
cin >> value;
while (cin.fail() || value <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Element [" << i << "] : ";
cin >> value;
}
q.enqueue(value);
}
system("cls");
continue;
}
else if (i == '8')
{
system("cls");
if (q.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
int search;
cout << "Enter Value You Want To Search It : ";
cin >> search;
while (cin.fail() || search <= 0) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter Value You Want To Search It : ";
cin >> search;
}
q.isFound(search);
}
}
else if (i == '6')
{
if (q.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "Cleared Queue !\n";
q.clear();
}
}
else if (i == '3')
{
if (q.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
system("cls");
cout << "\n";
q.print();
cout << endl << endl;
}
}
else if (i == '4')
{
system("cls");
if (q.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
cout << " The Rear Value " << q.get_rear() << endl;
}
else if (i == '5')
{
system("cls");
if (q.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
cout << "The Front Value Is : " << q.get_front() << endl;
}
else if (i == '2')
{
system("cls");
if (q.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
{
cout << "Delete The Value " << q.get_front();
q.dequeue();
cout << "\n";
}
}
else if (i == '7')
{
system("cls");
if (q.isEmpty())
{
cout << "The Queue Is Empty \n";
Sleep(1500);
system("cls");
continue;
}
else
cout << "The Number Of Node Is : " << q.count() << endl;
}
else if (i == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
else if (opt == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
else if (ch == '4')
{
int choice = 0;
int size_arr = 0;
int* arr = new int[size_arr];
while (true)
{
cout << "Enter The Size Of The Array : ";
cin >> size_arr;
while (cin.fail() || size_arr <= 0) {
cout << "Invalid input, please enter a positive number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Enter The Size Of The Array : ";
cin >> size_arr;
}
cout << "Enter The Elements Of The Array:\n";
for (int i = 0; i < size_arr; ++i)
{
cout << "Element " << i + 1 << ": ";
cin >> arr[i];
while (cin.fail()) {
cout << "Invalid input, please enter a number." << endl;
cin.clear();
cin.ignore(1000, '\n');
cout << "Element " << i + 1 << ": ";
cin >> arr[i];
}
}
cout << "\n [1] Bubble Sorting " << endl;
cout << " [2] Slection Sorting " << endl;
cout << " [3] Insertion Sorting " << endl;
cout << " [4] Merge Sorting " << endl;
cout << " [5] Quick Sorting " << endl;
cout << " [0] Return Menu " << endl;
char ots = _getch();
if (ots == '1')
{
system("cls");
bubbleSort(arr, size_arr);
}
else if (ots == '2')
{
system("cls");
selectionSort(arr, size_arr);
}
else if (ots == '3')
{
system("cls");
insertionSort(arr, size_arr);
}
else if (ots == '4')
{
system("cls");
mergeSort(arr, 0, size_arr - 1);
}
else if (ots == '5')
{
system("cls");
quickSort(arr, 0, size_arr - 1);
}
else if (ots == '0')
{
system("cls");
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
cout << "Sorted Array : \n ";
for (int i = 0; i < size_arr; ++i)
{
cout << arr[i] << " | ";
}
cout << "\n\n [1] To ReEnter An Array\n [0] Return.\n";
ots = _getch();
if (ots == '1')
{
system("CLS");
continue;
}
else if (ots != '0')
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
else
{
system("CLS");
break;
}
}
}
else if (ch == '5')
{
while (true)
{
cout << " - Math Operations - \n";
math_Operations();
cout << "\n [1] Another Equation ...\n [0] Return\n";
char op = _getch();
system("CLS");
if (op == '1')continue;
else if (op != '0')
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(1000);
system("cls");
break;
}
else
break;
}
}
else if (ch == '0')
{
cout << "Thank You For Using Our Program ^_^ \n\n\n\n\n";
break;
}
else
{
system("cls");
cout << "- Invalid Input, Try Again \n\n";
Sleep(2000);
system("cls");
continue;
}
}
}
void bubbleSort(int arr[], int size_arr) {
for (int i = 0; i < size_arr - 1; ++i) {
for (int j = 0; j < size_arr - i - 1; ++j) {
if (arr[j] > arr[j + 1]) {
int temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
}
void mergeSort(int arr[], int left, int right) {
if (left < right) {
int mid = left + (right - left) / 2;
mergeSort(arr, left, mid);
mergeSort(arr, mid + 1, right);
merge(arr, left, mid, right);
}
}
void merge(int arr[], int left, int mid, int right) {
int n1 = mid - left + 1;
int n2 = right - mid;
int* L = new int[n1];
int* R = new int[n2];
for (int i = 0; i < n1; ++i) {
L[i] = arr[left + i];
}
for (int j = 0; j < n2; ++j) {
R[j] = arr[mid + 1 + j];
}
int i = 0, j = 0, k = left;
while (i < n1 && j < n2) {
if (L[i] <= R[j]) {
arr[k] = L[i];
++i;
}
else {
arr[k] = R[j];
++j;
}
++k;
}
while (i < n1) {
arr[k] = L[i];
++i;
++k;
}
while (j < n2) {
arr[k] = R[j];
++j;
++k;
}
delete[] L;
delete[] R;
}
void selectionSort(int arr[], int size_arr) {
for (int i = 0; i < size_arr - 1; ++i) {
int minIndex = i;
for (int j = i + 1; j < size_arr; ++j) {
if (arr[j] < arr[minIndex]) {
minIndex = j;
}
}
int temp = arr[i];
arr[i] = arr[minIndex];
arr[minIndex] = temp;
}
}
void insertionSort(int arr[], int size_arr) {
for (int i = 1; i < size_arr; ++i) {
int key = arr[i];
int j = i - 1;
while (j >= 0 && arr[j] > key) {
arr[j + 1] = arr[j];
--j;
}
arr[j + 1] = key;
}
}
void quickSort(int arr[], int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
int partition(int arr[], int low, int high) {
int pivot = arr[high];
int i = low - 1;
for (int j = low; j <= high - 1; ++j) {
if (arr[j] < pivot) {
++i;
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int temp = arr[i + 1];
arr[i + 1] = arr[high];
arr[high] = temp;
return i + 1;
}