Tuesday, November 30, 2021

Coding Challange 2

 Question : arr[1, 2, 3, 4, 5, 6, 7] ko arr[4, 5, 6, 7, 1, 2, 3] banana hai .


#include<stdio.h>
void reverse(int* arr) {
    int frst = 0;
    int temp;
    int i;
    int j;
    while(frst != 3) {
        temp = arr[0];
        for(i = 1; i<=6; i++) {
            arr[i - 1] = arr[i];
        }
        arr[6] = temp;
        frst++;
    }
    for( j = 0; j<=6; j++) {
        printf("%d", arr[j]);
    }
}
int main() {
    int arr[7] = {1, 2, 3, 4, 5, 6, 7};
    reverse(arr);
    return 0;
}
//4567 123

Monday, November 29, 2021

StrCpy Implementation

 #include<stdio.h>
void fncpy(char* str2, char* str1) {
    int i = 0;
    while(*str1 != '\0') {
        str2[i] = *str1;
        i++;
        str1++;
    }
    *str1 = '\n'; //Isse lagana padega qki compiler khud ye copy nahi kareaga
    printf("Content from str2 to str1 is %s", str2);
}
int main() {
    char str1[5] = "atul";
    char str2[5];
    fncpy(str2, str1);
    return 0;
}

Strcmp implementation by self, while mein dhyan de do conditions par check kar raha hai

 #include<stdio.h>
int fnCmp(char* str1, char* str2) {
    while( (*str1 != '\0' && *str2 != '\0') && (*str1 == *str2)) {
        str1++;
        str2++;
    }
    if(*str1 == *str2)
       return 0;
    else
       return *str1 - *str2;
}
int main() {
    char str1[] = "abc";
    char str2[] = "abc";
    int x = fnCmp(str1, str2);
    if(x == 0) {
        printf("Strings Are Same");
    } else {
        printf("Strings Are not Same");
    }
    return 0;
}

Strings {pata nahi direct concatination bhi hota hai}

 #include<stdio.h>

int main() {
    
    char name[10] = {'s', 't', 'r', 'i', 'n', 'g'};
    printf("%s", name);
    char *str = "Hello World";
    printf("\n");
    while(*str != '\0') {
        printf("%c", *str);
        str = str + 1;
    }


    printf("\n");
    printf("%c", "Hello"[0]);


    printf("\n");
    printf("%c", *("Atul" + 0));


    printf("\n");


    printf("Ashish\
    Madarchod\
    Hai \n");


    printf("Ashish""Madarchod""Tha""Hai""Aur""Rehega");
}

Passing 2D Array to a function (2D Array Haua nahi hai normal array ki tarah he behave karta hai)

 #include<stdio.h>
void fun(int (*ptr)[4]) {
    for(int i = 0; i<=2; i++) {
        printf("Address of i block of arr %p\n", ptr + i);
        for(int j = 0; j<=3; j++) {
            printf("arr[%d][%d] = %d\n",i,j,*(*(ptr + i) + j) );
        }
    }
};
int main() {
    int arr[3][4] = {
      {11, 12, 13, 14},
      {15, 16, 17, 18},
      {19, 20, 21, 22}
    };
    
    int (*ptr)[4] = arr;
    
    fun(ptr);
    
    
    return 0;
}

2D Array

 What is 2D Array ?

A 2D array is actually a 1-D array in which each element is itself a 1-D array


#include<stdio.h>
int main() {
    int arr[3][4] = {
      {11, 12, 13, 14},
      {15, 16, 17, 18},
      {19, 20, 21, 22}
    };
    
    int (*ptr)[4] = arr;
    
    for(int i = 0; i<=2; i++) {
        printf("Address of i block of arr %p\n", ptr + i);
        for(int j = 0; j<=3; j++) {
            printf("arr[%d][%d] = %d\n",i,j,*(*(ptr + i) + j) );
        }
    }
    return 0;
}

Sunday, November 28, 2021

Insertion Sort (if pehle wala bada hai toh jagah change kar aise karte jaana hai condition for loop ke andar lagana hai)


#include<stdio.h>
int main() {
    int temp;        
    int arr[6] = {30, 45, 12, 51, 19, 8};
    for(int i = 1; i<=5; i++) {
          
             for(int j = i; j>0; j--) {
                 
                 if(arr[j-1] > arr[j]) {
                     temp = arr[j -1];
                     arr[j -1] = arr[j];
                     arr[j] = temp;
                 }
                 
             }
            
    }
    
    for(int k = 0; k<=5; k++) {
                printf("%d ", arr[k]);
            }
         return 0;
}

Saturday, November 27, 2021

bubble sort

 #include<stdio.h>
int main() {
    int arr[5] = {44, 33, 55, 22, 11};
    int temp;
    
    for(int i = 0; i<=3; i++) {
        for(int j = 0; j<=3; j++ ) {
            if(arr[j] > arr[j + 1]) {
                temp = arr[j];
                arr[j] = arr[j + 1];
                arr[j+1] = temp;
            }
        }
    }
    
    for(int i = 0; i<=4; i++) {
        printf("%d", arr[i]);
    }
    return 0;
}

implementation of selction sort algorithm on an unsorted array ( sorting array elements ).......

 #include<stdio.h>
int main() {
    int arr[5] = {44, 33, 55, 22, 11};
    int temp;
    
    for(int i = 0; i<=4; i++) {
        for(int j = i + 1; j<=5 ;j++) {
            if(arr[i] > arr[j]){
                temp = arr[i];
                arr[i] = arr[j];
                arr[j] = temp;
            }
        }
    }
    
    for(int i = 0; i<=4; i++) {
        printf("%4d", arr[i]);
    }


    
    return 0;
}

Doubly linked list---Opt [Insertion left, right, mid (from left, right), search , delete(first, last, mid), traversal]

 //See sabse pehle ek khali node bana lena jiska prev and next null ho uske bad use return kar le fir saare operation perform kar lena

//Time taken to make all these < 2.5 hrs (including logic making error and testing)

#include<stdio.h>
#include<stdlib.h>
struct node {
    struct node* prev;
    int data;
    struct node* next;
};
struct node* insBeg(struct node* head, int val) {
    struct node* temp = malloc(sizeof(struct node));
    temp->prev = NULL;
    temp->data = val;
    temp->next = NULL;
    head = temp;
    return (head);
}
void insLeft(struct node** head, int val) {
    struct node* temp = malloc(sizeof(struct node));
    if(((*head)->next == NULL) && ((*head)->prev == NULL)) {
        temp->prev = NULL;
        temp->data = val;
        temp->next  = *head;
        (*head)->prev = temp;
        *head = temp;
    } else {
        temp->next = *head;
        temp->data = val;
        temp->prev = NULL;
        (*head)->prev = temp;
        *head = temp;
    }
    
}
void insLeftMid(struct node** head, int val, int pos, char prep) {
    //Making of Temporary node;
    struct node* temp = malloc(sizeof(struct node));
    //Making of current and prevous pointer for mid value Insertion
    struct node* previous = *head;
    struct node* current = *head;
    //Calculate total number of nodes;
    struct node* for_num_nodes = *head;
    int tot_num_nodes = 0;
    while(for_num_nodes != NULL) {
        tot_num_nodes++;
        for_num_nodes = for_num_nodes->next;
    }
    printf("Total Num of Nodes %d\nNode after mid Insertion\n", tot_num_nodes);
    if(pos == 1) {
        printf("function had made for this, use that\n");
    }else if(pos == tot_num_nodes) {
        printf("Insertion after last node, Rukiye jara\n");
    } else {
        if(prep == 'a') {
        int i;
        for(i = 1; i<=pos; i++) {
            previous = current;
            current = current->next;
            // printf("%d", i);
        }
        // printf("pos =%d val = %d", pos, val);
        temp->prev = previous;
        temp->data = val;
        temp->next = current;
        current->prev = temp;
        previous->next = temp;
      } else {
        int i;
        for(i = 1; i<=pos-2; i++) {
            previous = current;
            current = current->next;
            // printf("%d", i);
        }
        temp->prev = previous;
        temp->data = val;
        temp->next = current;
        current->prev = temp;
        previous->next = temp;
      }
        
       
    }
    
}
void insRight(struct node** head, int val) {
    struct node *temp = malloc(sizeof(struct node));
    if(((*head)->next==NULL) && ((*head)->prev==NULL)) {
        temp->prev = *head;
        temp->data = val;
        temp->next = NULL;
        (*head)->next = temp;
    } else {
        //While loop use karenge taaki ham last node ka pata kar sakej;
        struct node* chk = *head;
        while(chk->next != NULL) {
            chk = chk->next;
        }
        chk->next = temp;
        temp->prev = chk;
        temp->data = val;
        temp->next = NULL;
    }
}
void delLeft(struct node** head, int del_pos) {
    //Calculate total number of nodes;
    struct node* for_num_nodes = *head;
    struct node* temp_del = *head;
    int tot_num_nodes = 0;
    while(for_num_nodes != NULL) {
        tot_num_nodes++;
        for_num_nodes = for_num_nodes->next;
    }
    
    if(*head == NULL) {
        printf("node is Empty");
    } else if(del_pos == 1) {
        struct node* temp_del = *head;
        *head = (*head)->next;
        free(temp_del);
        temp_del = NULL;
    } else if(del_pos == tot_num_nodes){
        struct node* chk = *head;
        while(chk->next != NULL) {
            chk = chk->next;
        }
        chk->prev->next = NULL;
        free(chk);
       
    } else {
        struct node* to_find = *head;
        struct node* del_node = NULL;
        struct node* prv = *head;
        int i;
        for(i = 1; i<=del_pos-1; i++) {
            prv = to_find;
            to_find = to_find->next;
        }
        del_node = to_find;
        prv->next = to_find->next;
        to_find->next->prev = to_find->prev;
        free(to_find);
        
    }
}
void printAll(struct node* head) {
    struct node* p = head;
    while(p != NULL) {
        printf("%d->", p->data);
        p = p->next;
    }
}
void search(struct node** head, int val) {
    struct node* to_search = *head;
    int nums = 0;
    while(to_search != NULL) {
        if(to_search->data == val) {
            nums = 1;
            break;
        } else {
            to_search = to_search->next;
            nums = 0;
        }
    }
    if(nums == 1)
        printf("\nData is present");
     else
        printf("\nsorry no such data exists");
    
    
    
}
int main() {
    struct node* head = NULL;
    struct node* empty = insBeg(head, 0);
    //printf("%d", take->data);
    insLeft(&empty, 1);
    insLeft(&empty, 2);
    insLeft(&empty, 3);
    insLeft(&empty, 4);
    insLeft(&empty, 5);
    //printAll(take);
    //insRight(&empty, 1);
    //insRight(&empty, 2);
    //insRight(&empty, 3);
    //printAll(empty);
    printAll(empty);
    /*Insert after any given postion, isko ham insLeft() function ki help se karenge
    mean left mein already kuch elements bhare hong;*/
 
    //insLeftMid(&empty, 9, 4, 'a');
    //Deliting nodes
    delLeft(&empty, 6);
    printf("\n");
    printAll(empty);
    search(&empty, 6);
    
    
    
    return 0;
}

Thursday, November 25, 2021

Circular Linked, Deletion [ Start, At Any Position, End ] Important...

/*Circular Singly linked list ka Insertion, Traversal, Searching, Deletion(Start, at any position, End) */

/*ka program hai */ 

//Deletion mein sabse jyada sochna pada hai normal linked list mein problem nahi hui Q dekh lena ek bar

/*Deletion mein agar position 1 ke liye alag  block of code likhe hai else mein yani (last_position -1) positions ke liye alag (last_position)  ke liye alag iss liye hoga qki (last_position -1) mein hame tail jo ki first circular list ko point kar raha hai use update nahi karn padta tha agar ham le bhi lenge uss code ko last position ke liye toh tail fir bhi wahi point karega jaha wo pehle kar raha tha yani deleted last node ko*/


/*last position deletion mein jo pointer position -1 place par hoga use tail banana hoga*/

#include<stdio.h>

#include<stdlib.h>

struct node {

    int data;

    struct node* next;

};

void add(struct node** tail, int val) {

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

    if(*tail == NULL) {

        temp->data = val;

        temp->next = temp;

        *tail = temp;

    } else {

        temp->data = val;

        temp->next = (*tail)->next;

        (*tail)->next = temp;

    }

}

void disp(struct node* tail) {

   if(tail == NULL)

     printf("NULL");

   else {

       struct node* p = tail->next;

       do {

           printf("<-%d", p->data);

           p = p->next;

       }while(p!=tail->next);

       

   }

}

int search(struct node* tail, int val) {

    if(tail == NULL){

        printf("list is empty");

    } else {

        struct node* p = tail->next;

        do {

            if(p->data == val){

                 return 1;

              break;

            }

            else {

                p = p->next;

            }

        } while(p!=tail->next);

        return -1;

    }

}


void deleteNode(struct node** tail, int position) {

    struct node* p = (*tail)->next;

    struct node* temp ;

    struct node* previous ;

    if(*tail == NULL) {

        printf("NULL");

    }

    else if(position == 1) {

        (*tail)->next = p->next; //Updating tails next to next node

        free(p);

        p = NULL;

    }else {

        int num_of_nodes = 0;

        do {

            num_of_nodes++;

            p = p->next;

        } while(p != (*tail)->next);

           printf("\nnumber of nodes = %d", num_of_nodes);

           

        

        if(position == num_of_nodes) {

            printf("\nnumber of nodes == position");

            int i;

            for(i = 1; i<=(position-1); i++) {

                previous = p;

                p = p->next;

            }

            temp = p;

            previous->next = p->next;

            *tail = previous;

            free(temp);

            temp = NULL;

        } else {

            printf("\nnumber of nodes != position");

            int i;

            for(i = 1; i<=(position-1); i++) {

                previous = p;

                p = p->next;

            }

            temp = p;

            previous->next = p->next;

            free(temp);

            temp = NULL;

        }

        

    }

    

}


int main() {

    int search_val = 4;

    int del_pos = 3;

    struct node* tail = NULL;

    add(&tail, 1);

    add(&tail, 2);

    add(&tail, 3);

    add(&tail, 4);

    add(&tail, 5);

    add(&tail, 6);

    disp(tail);

   int x = search(tail, search_val);

   if(x==1) {

       printf("\nsearch result found");

   } else {

       printf("\nsearch result not found");

   }

   deleteNode(&tail, 5);

   printf("\n");

   disp(tail);

   


    return 0;

}

Circular Linked List : deleting first position node

 #include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node* next;
};
void add(struct node** tail, int val) {
    struct node* temp = malloc(sizeof(struct node));
    if(*tail == NULL) {
        temp->data = val;
        temp->next = temp;
        *tail = temp;
    } else {
        temp->data = val;
        temp->next = (*tail)->next;
        (*tail)->next = temp;
    }
}
void disp(struct node* tail) {
   if(tail == NULL)
     printf("NULL");
   else {
       struct node* p = tail->next;
       do {
           printf("<-%d", p->data);
           p = p->next;
       }while(p!=tail->next);
       
   }
}
int search(struct node* tail, int val) {
    if(tail == NULL){
        printf("list is empty");
    } else {
        struct node* p = tail->next;
        do {
            if(p->data == val){
                 return 1;
              break;
            }
            else {
                p = p->next;
            }
        } while(p!=tail->next);
        return -1;
    }
}

void deleteNode(struct node** tail, int position) {
    
    struct node* p = (*tail)->next;
    (*tail)->next = p->next; //Updating tails next to next node
    free(p);
    p = NULL;
}

int main() {
    int search_val = 4;
    int del_pos = 3;
    struct node* tail = NULL;
    add(&tail, 0);
    add(&tail, 1);
    add(&tail, 2);
    add(&tail, 3);
    add(&tail, 4);
    add(&tail, 5);
    disp(tail);
   int x = search(tail, search_val);
   if(x==1) {
       printf("\nsearch result found");
   } else {
       printf("\nsearch result not found");
   }
   deleteNode(&tail, 1);
   printf("\n");
   disp(tail);
   

    return 0;
}

Search in Circular linked list

 #include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node* next;
};
void add(struct node** tail, int val) {
    struct node* temp = malloc(sizeof(struct node));
    if(*tail == NULL) {
        temp->data = val;
        temp->next = temp;
        *tail = temp;
    } else {
        temp->data = val;
        temp->next = (*tail)->next;
        (*tail)->next = temp;
    }
}
void disp(struct node* tail) {
   if(tail == NULL)
     printf("NULL");
   else {
       struct node* p = tail->next;
       do {
           printf("%d", p->data);
           p = p->next;
       }while(p!=tail->next);
       
   }
}
int search(struct node* tail, int val) {
    if(tail == NULL){
        printf("list is empty");
    } else {
        struct node* p = tail->next;
        do {
            if(p->data == val){
                 return 1;
              break;
            }
            else {
                p = p->next;
            }
        } while(p!=tail->next);
        return -1;
    }
}
int main() {
    struct node* tail = NULL;
    add(&tail, 0);
    add(&tail, 1);
    add(&tail, 2);
    add(&tail, 3);
    add(&tail, 4);
    add(&tail, 5);
    disp(tail);
   int x = search(tail, 4);
   if(x==1) {
       printf("\nsearch result found");
   } else {
       printf("\nsearch result not found");
   }

    return 0;
}

Wednesday, November 24, 2021

Implementing circular list auto

 #include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node* next;
};
void add(struct node** tail, int val) {
    struct node* temp = malloc(sizeof(struct node));
    if(*tail == NULL) {
        temp->data = val;
        temp->next = temp;
        *tail = temp;
    } else {
        temp->data = val;
        temp->next = (*tail)->next;
        (*tail)->next = temp;
    }
}
void disp(struct node* tail) {
   if(tail == NULL)
     printf("NULL");
   else {
       struct node* p = tail->next;
       do {
           printf("%d", p->data);
           p = p->next;
       }while(p!=tail->next);
       
   }
}
int main() {
    struct node* tail = NULL;
    add(&tail, 0);
    add(&tail, 1);
    add(&tail, 2);
    add(&tail, 3);
    add(&tail, 4);
    add(&tail, 5);
    disp(tail);

    return 0;
}

Tuesday, November 23, 2021

Manual Circular linked list


Preet ma'ams challange to insert element in sorted list at beggnjing at last and at middle

 #include<stdio.h>

#include<stdlib.h>

struct node {

    int data;

    struct node* next;

};

void inElFr(struct node** head, int val) {

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

    temp->data = val;

    temp->next = NULL;

    if(*head == NULL)

      *head = temp;

      else {

          struct node* run = *head;

          while(run->next != NULL) {

              run = run->next;

          }

            run->next = temp;

       }

}

void midInsert(struct node** head, int elt) {

    struct node* find = *head;

    struct node* prvs = *head;

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

    

     if(elt < find->data) {

         

         temp->data = elt;

         temp->next = *head;

         *head = temp;

         

     } else {

         while(find->next != NULL) {

        if(find->data > elt) {

            break;

        } else {

            prvs = find;

            find = find->next;

        }

            }if(find->next = NULL) {

                temp->data = elt;

                prvs->next = temp;

                temp->next = find;

            } else {

                temp->data = elt;

                temp->next = NULL;

                prvs->next->next = temp;

            }

    

     }

       

    

    

}

void shElFr(struct node* head) {

    struct node* sho = head;

    while(sho!=NULL) {

        printf("%d->", sho->data);

        sho = sho->next;

    }

    printf("Reached");

}

int main() {

    int num;

    struct node* head = NULL;

    inElFr(&head, 10);

    inElFr(&head, 20);

    inElFr(&head, 40);

    inElFr(&head, 50);

    shElFr(head);

    printf("\n Enter the number \t");

    scanf("%d", &num);

    midInsert(&head, num);

    shElFr(head);


    

    return 0;

}

Monday, November 22, 2021

sorted insertion....With Last insertion

 #include<stdio.h>
#include<stdlib.h>
struct node {
    int data;
    struct node* next;
};
void inElFr(struct node** head, int val) {
    struct node* temp = (struct node*)malloc(sizeof(struct node));
    temp->data = val;
    temp->next = NULL;
    if(*head == NULL)
      *head = temp;
      else {
          struct node* run = *head;
          while(run->next != NULL) {
              run = run->next;
          }
            run->next = temp;
       }
}
void midInsert(struct node** head, int elt) {
    struct node* find = *head;
    struct node* prvs = *head;
    struct node* temp = malloc(sizeof(struct node));
    while(find->next != NULL) {
        if(find->data > elt) {
            break;
        } else {
            prvs = find;
            find = find->next;
        }
    }
    temp->data = elt;
    prvs->next = temp;
    temp->next = find;
    
}
void shElFr(struct node* head) {
    struct node* sho = head;
    while(sho!=NULL) {
        printf("%d->", sho->data);
        sho = sho->next;
    }
    printf("Reached");
}
int main() {
    int num;
    struct node* head = NULL;
    inElFr(&head, 10);
    inElFr(&head, 20);
    inElFr(&head, 30);
    inElFr(&head, 50);
    shElFr(head);
    printf("\n Enter the number \t");
    scanf("%d", &num);
    midInsert(&head, num);
    shElFr(head);

    
    return 0;
}

Deleting node from given position

 #include <stdio.h>
#include <stdlib.h>
struct node
{
    int data;
    struct node *next;
};

void push(struct node** head_ref, int new_data)
{
    struct node* new_node = (struct node*) malloc(sizeof(struct node));
    new_node->data = new_data;
    new_node->next = (*head_ref);
    (*head_ref) = new_node;
}

void show(struct node* sho) {
    while(sho!=NULL){
        printf("%d", sho->data);
        sho = sho->next;
    }
    printf("Reached");
}
void deleteNode(struct node **head, int position) {
    struct node* current = *head;
    struct node* previous;
    struct node* temp;
    if(*head == NULL){
        printf("List is Empty");
    } else if(position == 1) {
        temp = *head;
        *head = (*head)->next;
        free(temp);
        temp = NULL;
    } else {
        int i;
        for(i = 1; i<=(position - 1); i++) {
            previous = current;
            current = current->next;
        }
        temp = current;
        previous->next = current->next;
        free(temp);
        temp = NULL;
    }
       
}
int main()
{
    struct node* head = NULL;
    push(&head, 4);
    push(&head, 3);
    push(&head, 2);
    push(&head, 1);
    show(head);
    deleteNode(&head, 1);
    show(head);
    return 0;
}

Monday, November 1, 2021

Linked list in C Data Structure

 #include<stdio.h>
struct tag {
    int x;
    struct tag *Next;
};
void showMe(struct tag *n) {
    while(n!=NULL) {
        printf("%d\n", n->x);
         n = n->Next;
    }
}
int main() {
    struct tag x, *t1, y , *t2, z, *t3;
    t1 = &x;
    t2 = &y;
    t3 = &z;
    
    t1->x = 1;
    t1->Next = &y;
    t2->x = 2;
    t2->Next = &z;
    t3->x = 3;
    t3->Next = NULL;
    
    showMe(&x);

    return 0;
}

Linked List Data Structure

 using namespace std;
#include<iostream>
class Node {
public:
    int Value;
    Node* Next;
};

void print_node(Node* n) {
    while (n!=NULL) {
        cout << n->Value << endl;
        n = n->Next;
    }
}


int main() {

    Node* head = new Node();
    Node* second = new Node();
    Node* third = new Node();

    head->Value = 1;
    head->Next = second;

    second->Value = 2;
    second->Next = third;
    
    third->Value = 3;
    third->Next = NULL;

    print_node(head);


    system("pause > 0");
    return 0;
}

Queue Data Structure

 using namespace std;
#include<iostream>
#define N 20
class Queue {
public:
    int* arr;
    int front;
    int back;

    Queue() {
        arr = new int[N];
        front = -1;
        back = -1;
    }

  //functions to be made push(); peak(); pop(); empty(); Queue(); ~Queue();

    void push(int x) {
        if (back == N - 1) {
            cout << "Stack Overflowed" << endl;
            return;
        }

        back++;
        arr[back] = x;

        if (front == -1) {
            front++;
        }
    }

    void pop() {
        if (front == -1 || front > back) {
            cout << "Stack UnderFlow" << endl;
            return;
        }
        front++;
    }

    int peek() {
        if (front == -1 || front > back) {
            cout << "Stack is Empty" << endl;
            return -1;
        }
        return arr[front];
    }

    bool empty() {
        if (front == -1 || front > back) {
            return true;
        }
        return false;
    }

    ~Queue() {
        delete[] arr;
        cout << "Deallocated All the Resources to Computer Again@" << endl;
    }
};
int main() {

    Queue q;
    q.push(1);
    q.push(2);
    q.push(3);
    q.push(4);

    cout << q.peek() << endl;
    q.pop();

    cout << q.peek() << endl;
    q.pop();

    cout << q.peek() << endl;
    q.pop();

    cout << q.empty() << endl;

    

    system("pause > 0");
    return 0;
}

Priority queue deleting elements after ascending inputs Gaand Fadd

 using namespace std; #include<iostream> #define N 5 class pq { public:     int* arr;     int front;     int rear;     pq() {         ...