Skip to content

datastructure file updated #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
129 changes: 66 additions & 63 deletions Queue_using_array.c
Original file line number Diff line number Diff line change
@@ -1,77 +1,80 @@
#include<stdio.h>
#include<malloc.h>
#include<limits.h>
//structure of Queue
struct queue
{
int front,rear,size;
unsigned capacity;
int *array;
};
#include <stdio.h>
#include<stdlib.h>
#define MAX 50
void insert();
void delete();
void display();
int queue_array[MAX];
int rear = - 1;
int front = - 1;

struct queue *create(unsigned capacity)
int main()
{
struct queue *Queue=(struct queue*)malloc(sizeof(struct queue));
Queue->capacity=capacity;
Queue->front=Queue->size=0;
Queue->rear=capacity-1;
Queue->array=(int*)malloc(capacity*sizeof(int));
return Queue;
}

int isEmpty(struct queue *Queue)
int choice;
while (1)
{
return(Queue->size==0);
}

int isFULL(struct queue *Queue)
printf("1.Insert element to queue n");
printf("2.Delete element from queue n");
printf("3.Display all elements of queue n");
printf("4.Quit n");
printf("Enter your choice : ");
scanf("%d", &choice);
switch(choice)
{
return(Queue->size==Queue->capacity);
case 1:
insert();
break;
case 2:
delete();
break;
case 3:
display();
break;
case 4:
exit(1);
default:
printf("Wrong choice n");
}

void enqueue(struct queue *Queue,int n)
{
if(isFull(Queue))
return;
Queue->rear=(Queue->rear+1)%Queue->capacity;
Queue->array[Queue->rear]=n;
Queue->size=Queue->size+1;
printf("Enqueued Element%d",n);
}

int dequeue(struct queue *Queue)
}
void insert()
{
if (isEmpty(Queue))
return 0;
int item=Queue->array[Queue->front];
Queue->front=(Queue->front+1)%Queue->capacity;
Queue->size=Queue->size-1;
return(item);
int item;
if(rear == MAX - 1)
printf("Queue Overflow n");
else
{
if(front== - 1)
front = 0;
printf("Inset the element in queue : ");
scanf("%d", &item);
rear = rear + 1;
queue_array[rear] = item;
}

int front(struct queue *Queue)
}
void delete()
{
int item=Queue->array[Queue->front];
return(item);
if(front == - 1 || front > rear)
{
printf("Queue Underflow n");
return;
}

int rear( struct queue *Queue)
else
{
int item=Queue->array[Queue->rear];
return(item);
printf("Element deleted from queue is : %dn", queue_array[front]);
front = front + 1;
}

int main()
}
void display()
{
struct queue *Queue=create(50);
enqueue(Queue,12);
enqueue(Queue,13);
enqueue(Queue,14);
enqueue(Queue,15);
enqueue(Queue,16);

dequeue(Queue);
printf("Element At front %d\n\n",front(Queue));
printf("Element At Rear%d",rear(Queue));
return 0;
int i;
if(front == - 1)
printf("Queue is empty n");
else
{
printf("Queue is : n");
for(i = front; i <= rear; i++)
printf("%d ", queue_array[i]);
printf("n");
}
}
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
# basic_datastructure_programs
# This repo consists of all programs related to basic data structures.
# This repo consists of all programs related to basic data structures step by step.
# Easy to understand the concept.