Khaled Mamdooh Ahmed
Khaled Mamdooh Ahmed
# include <iostream>
struct node
int data;
node * next;
};
void errorMassage(){
cout<<"=============================================\n\n";
{ int number;
do
return number;
cout<<"==============================================\n";
int index = 0;
cout<<"==========================================\n";
else {
cout << "the index "<< index << " has the value "<< arr[index] <<endl;
cout<<"==========================================\n";
cin>> number;
cout << "The number "<< number <<" found at index "<< mid << endl;
cout<<"==========================================\n";
return 0;
low = mid + 1 ;
else
high = mid - 1 ;
cout << "The number "<< number <<" is not in the array \n";
cout<<"==========================================\n";
return 1;
if (length == 0){
cout<<"====================\n";
else{
int search ;
cin>>search;
cout<<"==================\n";
if(arr[i] == search){
cout<<"==============================\n";
return ;
cout<<"==============================\n";
cout<<"=======================================\n";
else {
cout<< "=================================\n";
return i;
cout<< "====================================\n";
return -101;
short choies;
cout<< "Do you wnat to delete the number by the value or by tht index \n";
cout<< "Perss 0 to go with the index or any number to go with numbers \n";
cin>> choies;
int index = 0;
if (choies != 0)
{
back:
int number;
cin>> number;
if(index == -101){
goto back;
else
cout<<"==========================================\n";
return 1;
length--;
cout<< "=====================================\n";
return 0 ;
}
cout<< "===========================\n";
cout<<endl;
cout<< "===========================\n\n";
int choose ;
cin>> choose;
cout<<"=============\n";
switch (choose)
case 1:
linearSearch(arr ,length);
break;
case 2:
break;
default:
errorMassage();
break;
}
void startArray ()
cout<< "\t=============================";
fillThearray(arr , length);
int counter = 0 ;
int num = 0;
cout<< "==================================================\n";
cin>> num;
switch (num)
case 1:
case 2:
case 3:
case 5:
case 6:
case 7:
return;
default :
errorMassage();
break;
++counter;
do
cin>> newNode->data;
if (head == NULL)
temp->next = newNode;
temp = newNode;
cout<<"==========================\n";
cin>>choose;
if (choose == 0)
temp = head;
cout<<"==========================\n";
cout<<"\n==========================\n";
} while (choose);
int counter = 0;
node * temp;
temp = head;
counter++;
temp = temp->next;
return counter;
newNode->next = head;
head = newNode;
cout<<"==========================\n";
node * temp;
temp = head;
if (temp == NULL){
head = newNode;
cout<<"==========================\n";
}else{
temp = temp->next;
temp->next = newNode;
cout<<"==========================\n";
node *temp;
int position , i = 1;
cout<<"Enter the position that you want to insertion at \n";
cin>> position;
cout<<"=======================\n";
else if (position == 1)
else {
temp = head;
temp = temp->next;
i++;
newNode->next = temp->next;
temp->next = newNode;
cout<<"==========================\n";
int number;
cin>>number;
newNode->next = NULL;
int choose ;
cout<<"===============\n";
cin>> choose;
switch (choose)
case 1:
insterFromBeginning(head, newNode);
break;
case 2:
insterFromGivenPosition(head, newNode);
break;
case 3:
insterFromEnd(head, newNode);
break;
default:
errorMassage();
break;
if (head == NULL){
cout<<"==============================\n";
}
else{
temp = head;
head = head->next;
delete(temp);
cout<<"==========================\n";
node * pre ;
int position , i = 1;
pre = head;
cout<<"=======================\n";
else{
i++;
if (head == NULL){
else if (position == 1)
deleteFromBeginning (head,temp);
else{
temp = pre->next;
delete(temp);
cout<<"==========================\n";
node * pre;
temp = head;
if (head == NULL){
cout<<"==============================\n";
return ;
pre = temp;
}
if(temp == head){
head = NULL;
delete(temp);
cout<<"==========================\n";
else{
delete(temp);
cout<<"==========================\n";
node * temp;
int choose ;
cout<<"=================\n";
cin>> choose;
cout<<"=================\n";
switch (choose)
case 1:
deleteFromBeginning(head ,temp);
break;
case 2:
deleteFromGivenPosition(head ,temp);
break;
case 3:
deleteFromEnd(head ,temp);
break;
default:
errorMassage();
break;
if (head == NULL){
cout<<"=======================\n";
else{
node * temp;
temp = head;
cout<<"\n======================\n";
node * temp;
cout<<"Enter the value \n";
cin>>number;
temp = head;
if (number == temp->data){
cout<<"The number " << temp->data <<" found at the node number " << counter <<endl;
cout<< "====================================\n";
return ;
temp = temp->next;
counter++;
cout<< "====================================\n";
void statrLinkedList(){
cout<<"\t ====================\n";
getnodes(head);
while (true)
cin>>choose;
switch (choose)
case 1:
insertionLinkedList(head);
break;
case 2:
deletionLinkedList(head);
break;
case 3:
displaylinkList(head);
break;
case 4:
searchLinkedList(head);
break;
case 5:
return;
default:
errorMassage();
break;
int number ;
cin>> number;
if (rear == ELEMENTS -1 ){
cout<<"Overflow \n";
cout<<"============\n";
front = rear = 0;
queue[rear] = number;
cout<<"==================================\n";
else {
queue[++rear] = number;
cout<<"==================================\n";
if (front == -1){
cout <<"========================\n";
cout<<"\n===========================\n";
front = rear = -1 ;
else{
cout<<"\n===========================\n";
}
void displayArrayQueue (int queue [ELEMENTS],int front ,int rear){
if (front == -1){
cout <<"====================\n";
else{
cout<<queue[i] <<"\t";
cout<<"\n====================\n";
if(front == -1 ){
cout <<"====================\n";
else{
cout<<"\n============================\n";
cout<<"============================== \n\n";
int choose = 0 ;
while (true)
switch (choose)
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
return 1;
case 6:
return -101;
default:
errorMassage();
break;
}
}
return 0;
int number ;
cin>> number;
newNode->data = number;
newNode->next = NULL;
if (front == NULL){
cout<<"==================================\n";
else{
rear->next = newNode;
rear = newNode;
cout<<"==================================\n";
if (front == NULL){
cout<< "========================\n";
else{
node * temp;
temp = front;
front = front->next;
delete(temp);
if (front == NULL){
cout<<"====================\n";
else{
node * temp;
temp = front;
temp = temp->next;
cout<<"\n====================\n";
if (front == NULL){
cout<<"====================\n";
else {
cout<<"The front of the queue is " << front->data;
cout<<"\n============================\n";
int startQueueLinkedList(){
cout<<"============================== \n\n";
int choose = 0 ;
while (true)
switch (choose)
case 1:
enqueueLinkedList (front,rear);
break;
case 2:
dequeueLiskedList (front);
break;
case 3:
displayListQueue (front);
break;
case 4:
peekqueueQueue(front);
break;
case 5:
return 1;
case 6:
return -101;
default:
errorMassage();
break;
return 0;
void startQueue(){
while (true)
cout <<"=====================================\n";
switch (choose)
{
case 1:
if (back == -101){
return ;
break;
case 2:
back = startQueueLinkedList();
if (back == -101){
return ;
break;
case 3:
return ;
default:
errorMassage();
break;
int number ;
if(top == ELEMENTS - 1 ){
cout<<"===================\n";
}
else {
cin>> number;
cout<<"==============================\n";
if (top == -1){
cout<<"Stack Underflow\n";
cout<<"=================\n";
else{
cout<<stack[top--] ;
cout<<"\n=========================\n";
if (top == -1){
else{
cout<<stack[i];
cout<<"\t";
}
}
cout<<"\n=================\n";
if (top == -1){
cout<< "====================\n";
else{
cout<<stack[top];
cout<<"\n===============\n";
cout<<"============================== \n\n";
int choose = 0 ;
while (true)
switch (choose)
{
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
return ;
default:
errorMassage();
break;
node * newNode;
int number ;
cin>> number;
newNode->data = number ;
newNode->next = top ;
top = newNode;
cout<<"=============================\n";
node * temp ;
temp = top;
if (top == NULL){
cout<<"Stack Underflow\n";
cout<<"=================\n";
else{
cout<<"\n======================\n";
top = top->next;
delete(temp);
if (top == NULL){
cout<<"Stack is empty\n";
cout<<"=================\n";
else{
node * temp;
temp = top;
{
cout<<temp->data << "\t";
cout<<"\n=====================\n";
if (top == NULL){
return 0;
else{
return top->data;
cout<<"============================== \n\n";
int choose = 0 ;
while (true)
case 1:
pushList (top);
break;
case 2:
popList (top);
break;
case 3:
displayListStack (top);
break;
case 4:
break;
case 5:
return ;
default:
errorMassage();
break;
int choose = 0 ;
while (true)
{
cout <<"=====================================\n";
switch (choose)
case 1:
startStackArray (stack);
return ;
case 2:
startStackLinkedList();
return;
default:
errorMassage();
break;
while (true)
cout<< "=======================================\n";
cout<< "=======================================\n";
short number = 0 ;
switch (number)
case 1:
startArray();
break;
case 2:
statrLinkedList();
break;
case 3:
startStack();
break;
case 4:
startQueue();
break;
case 5:
exit(0);
break;
default:
errorMassage();
break;
}
int main ()
startProgram();
return 0;