From 045bc513b5077db58cb5f32fd8b66f097df37c8d Mon Sep 17 00:00:00 2001 From: snehitha-30727 <2400030727@kluniversity.in> Date: Wed, 29 Oct 2025 13:15:36 +0530 Subject: [PATCH 1/2] Implement queue using two stacks --- Implement_queue_using_stacks | 54 ++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 Implement_queue_using_stacks diff --git a/Implement_queue_using_stacks b/Implement_queue_using_stacks new file mode 100644 index 000000000..d31b93c85 --- /dev/null +++ b/Implement_queue_using_stacks @@ -0,0 +1,54 @@ +#define MAX_CALL 100 + + +typedef struct { + int *in; + int *out; + int idx_in; + int idx_out; +} MyQueue; + + +MyQueue* myQueueCreate() { + MyQueue *queue = (MyQueue *)malloc(sizeof(MyQueue)); + if (queue == NULL) { + return NULL; + } + queue->in = (int *)malloc(MAX_CALL * sizeof(int)); + queue->out = (int *)malloc(MAX_CALL * sizeof(int)); + queue->idx_in = -1; + queue->idx_out = -1; + + return queue; +} + +void myQueuePush(MyQueue* obj, int x) { + obj->in[++obj->idx_in] = x; +} +int myQueuePeek(MyQueue* obj) { + if (obj->idx_out < 0) { + while (obj->idx_in >= 0) { + obj->out[++obj->idx_out] = obj->in[obj->idx_in--]; + } + } + + return obj->idx_out < 0 ? -1 : obj->out[obj->idx_out]; +} +int myQueuePop(MyQueue* obj) { + int front = myQueuePeek(obj); + + if (front != -1) { + obj->idx_out--; + } + + return front; +} +bool myQueueEmpty(MyQueue* obj) { + return obj->idx_in == -1 && obj->idx_out == -1; +} + +void myQueueFree(MyQueue* obj) { + free(obj->in); + free(obj->out); + free(obj); +} From d57125794cd48119c5a3ff3d3ab504073b0edb4c Mon Sep 17 00:00:00 2001 From: snehitha-30727 <2400030727@kluniversity.in> Date: Wed, 29 Oct 2025 13:55:27 +0530 Subject: [PATCH 2/2] Add Hash_divided_string file --- Hash_divided_string | 18 ++++++++++++ Implement_queue_using_stacks | 54 ------------------------------------ 2 files changed, 18 insertions(+), 54 deletions(-) create mode 100644 Hash_divided_string delete mode 100644 Implement_queue_using_stacks diff --git a/Hash_divided_string b/Hash_divided_string new file mode 100644 index 000000000..18e6dac86 --- /dev/null +++ b/Hash_divided_string @@ -0,0 +1,18 @@ +char* stringHash(char* s, int k) { + int n=strlen(s); + int length=n/k; + char* result=(char*)malloc(length+1); + if(!result){ + return NULL; + } + int index=0,i,j,sum; + for(i=0;iin = (int *)malloc(MAX_CALL * sizeof(int)); - queue->out = (int *)malloc(MAX_CALL * sizeof(int)); - queue->idx_in = -1; - queue->idx_out = -1; - - return queue; -} - -void myQueuePush(MyQueue* obj, int x) { - obj->in[++obj->idx_in] = x; -} -int myQueuePeek(MyQueue* obj) { - if (obj->idx_out < 0) { - while (obj->idx_in >= 0) { - obj->out[++obj->idx_out] = obj->in[obj->idx_in--]; - } - } - - return obj->idx_out < 0 ? -1 : obj->out[obj->idx_out]; -} -int myQueuePop(MyQueue* obj) { - int front = myQueuePeek(obj); - - if (front != -1) { - obj->idx_out--; - } - - return front; -} -bool myQueueEmpty(MyQueue* obj) { - return obj->idx_in == -1 && obj->idx_out == -1; -} - -void myQueueFree(MyQueue* obj) { - free(obj->in); - free(obj->out); - free(obj); -}