From 8fb006cc165a35fdf9028de704b1fe0e36673969 Mon Sep 17 00:00:00 2001 From: Deepak Patil <72160764+Deepcodr@users.noreply.github.com> Date: Fri, 7 Oct 2022 22:24:33 +0530 Subject: [PATCH 1/4] Add files via upload --- queue.c | 100 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 queue.c diff --git a/queue.c b/queue.c new file mode 100644 index 0000000..3553607 --- /dev/null +++ b/queue.c @@ -0,0 +1,100 @@ +#include +//queue +static int front=-1; +static int rear=-1; + +void enque(int queue[],int size) +{ + if(rear==size-1) + { + printf("Queue Overflow\n"); + return; + } + else if(front==-1) + { + int item; + printf("Enter item\n"); + scanf("%d",&item); + + front++; + rear++; + queue[rear]=item; + printf("%d inserted successfully\n",item); + } + else + { + int item; + printf("Enter item\n"); + scanf("%d",&item); + + rear++; + queue[rear]=item; + printf("%d inserted successfully\n",item); + } + return; +} + +void deque(int queue[]) +{ + if(front==-1 || front>rear) + { + printf("Queue Underflow\n"); + return; + } + else + { + int item=queue[front]; + front++; + printf("%d deque successful\n",item); + } + return; +} + +void display(int queue[]) +{ + if(front==-1) + { + printf("Queue Empty\n"); + return; + } + for(int i=front;i<=rear;i++) + { + printf("%d\t",queue[i]); + } + printf("\n"); +} + +int main() +{ + int size; + + printf("Enter size of queue\n"); + scanf("%d",&size); + + int queue[size]; + + int ch; + do{ + printf("Enter Your choice\n"); + printf("1.Enque\n2.Deque\n3.Display\n4.Exit\n"); + scanf("%d",&ch); + + switch(ch) + { + case 1: + enque(queue,size); + break; + case 2: + deque(queue); + break; + case 3: + display(queue); + break; + case 4: + break; + default: + printf("Enter a valid choice\n"); + } + }while(ch!=4); + return 0; +} \ No newline at end of file From cbd2af29eb11c3da34cb42f14c68ed8ca23b3dd1 Mon Sep 17 00:00:00 2001 From: Deepak Patil <72160764+Deepcodr@users.noreply.github.com> Date: Fri, 7 Oct 2022 22:26:20 +0530 Subject: [PATCH 2/4] Circular queue in c --- circularqueue.c | 135 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) create mode 100644 circularqueue.c diff --git a/circularqueue.c b/circularqueue.c new file mode 100644 index 0000000..2767d5a --- /dev/null +++ b/circularqueue.c @@ -0,0 +1,135 @@ +#include +//circular queue +static int REAR=-1; +static int FRONT=-1; + +void enque(int queue[],int size) +{ + if((REAR==size-1 && FRONT==0) || REAR==FRONT-1) + { + printf("Queue Overflow\n"); + return; + } + else + { + if(FRONT==-1) + { + FRONT++; + REAR++; + } + else if(REAR==size-1) + { + REAR=0; + } + else + { + REAR++; + } + int item; + printf("Enter Item insert: \n"); + scanf("%d",&item); + queue[REAR]=item; + printf("%d inserted successfully\n",item); + } + return; +} + +void deque(int queue[],int size) +{ + if(FRONT==-1) + { + printf("Queue Underflow\n"); + return; + } + else + { + printf("%d deleted successfully\n",queue[FRONT]); + if(FRONT==REAR) + { + FRONT=-1; + REAR=-1; + } + else if(FRONT==size-1) + { + FRONT=0; + } + else + { + FRONT++; + } + } + return; +} + +void display(int queue[],int size) +{ + printf("%d %d\n",FRONT,REAR); + if(FRONT==-1) + { + printf("Queue Empty\n"); + } + else + { + if(FRONT>REAR) + { + printf("Queue:\n"); + for(int i=FRONT;i Date: Fri, 7 Oct 2022 22:27:46 +0530 Subject: [PATCH 3/4] Delete circularqueue.c --- circularqueue.c | 135 ------------------------------------------------ 1 file changed, 135 deletions(-) delete mode 100644 circularqueue.c diff --git a/circularqueue.c b/circularqueue.c deleted file mode 100644 index 2767d5a..0000000 --- a/circularqueue.c +++ /dev/null @@ -1,135 +0,0 @@ -#include -//circular queue -static int REAR=-1; -static int FRONT=-1; - -void enque(int queue[],int size) -{ - if((REAR==size-1 && FRONT==0) || REAR==FRONT-1) - { - printf("Queue Overflow\n"); - return; - } - else - { - if(FRONT==-1) - { - FRONT++; - REAR++; - } - else if(REAR==size-1) - { - REAR=0; - } - else - { - REAR++; - } - int item; - printf("Enter Item insert: \n"); - scanf("%d",&item); - queue[REAR]=item; - printf("%d inserted successfully\n",item); - } - return; -} - -void deque(int queue[],int size) -{ - if(FRONT==-1) - { - printf("Queue Underflow\n"); - return; - } - else - { - printf("%d deleted successfully\n",queue[FRONT]); - if(FRONT==REAR) - { - FRONT=-1; - REAR=-1; - } - else if(FRONT==size-1) - { - FRONT=0; - } - else - { - FRONT++; - } - } - return; -} - -void display(int queue[],int size) -{ - printf("%d %d\n",FRONT,REAR); - if(FRONT==-1) - { - printf("Queue Empty\n"); - } - else - { - if(FRONT>REAR) - { - printf("Queue:\n"); - for(int i=FRONT;i Date: Fri, 7 Oct 2022 23:29:16 +0530 Subject: [PATCH 4/4] Bubblesort algorithm --- bubblesort_templates.cpp | 64 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 bubblesort_templates.cpp diff --git a/bubblesort_templates.cpp b/bubblesort_templates.cpp new file mode 100644 index 0000000..def3cd9 --- /dev/null +++ b/bubblesort_templates.cpp @@ -0,0 +1,64 @@ +#include +using namespace std; + +//templates in cpp. +//bubble sort template in cpp. + +template +void bubblesort(T *x,int count) +{ + register int a,b;//using register for faster execution. + T t; + + for(a=1;a=a;b--) + { + if(x[b-1]>x[b]) + { + //exchange elements + t=x[b-1]; + x[b-1]=x[b]; + x[b]=t; + } + } + } +}; + +int main() +{ + int arrayi[7]={3,4,2,1,6,5,7}; + double arrayd[7]={3.4,4.6,2.2,-1,6.8,5.1,7.9}; + + int i; + cout<<"unsorted integer array is :"<