Ads
Ads
Ads
#include <stdio.h>
#include <stdlib.h>
typedef struct {
char data[MAX];
} CircularQueue;
q->front=0;
q->rear=-1;
q->size=0;
if (isFull(q)){
printf("Queue Overflow\n");
}else{
q->rear=(q->rear+1)%MAX;
q->data[q->rear]=element;
q->size++;
}}
if (isEmpty(q)){
printf("Queue Underflow\n");
}else{
char element=q->data[q->front];
q->front=(q->front+1)%MAX;
q->size--;
}}
if(isEmpty(q)){
printf("Queue is empty\n");
}else{
int i=q->front;
for(int count=0;count<q->size;count++){
printf("%c ",q->data[i]);
i=(i+1) % MAX;
printf("\n");
int main() {
CircularQueue q;
initializeQueue(&q);
int choice;
char element;
do {
printf("4. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter the character to insert: ");
insertElement(&q, element);
break;
case 2:
deleteElement(&q);
break;
case 3:
displayStatus(&q);
break;
case 4:
printf("Exit\n");
break;
default:
printf("Invalid choice\n");
break;
return 0; }
8
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
int usn;
char name[10];
};
void insertionatfront(){
scanf("%s %d",&newnode->name,&newnode->usn);
if(head==NULL){
head=newnode;
newnode->next=NULL;
else{
newnode->next=head;
head=newnode;
void insertionatend(){
scanf("%s %d",&newnode->name,&newnode->usn);
if(head==NULL){
head=newnode;
newnode->next=NULL;
else{
while(temp->next!=NULL){
temp=temp->next;
temp->next=newnode;
newnode->next=NULL;
void deleteatfront(){
if(head==NULL){
else{
head=head->next;
free(temp);
void deleteatend(){
if(head==NULL){
else{
while(temp->next!=NULL){
prev=temp;
temp=temp->next;
prev->next=NULL;
free(temp);
void display(){
if(head==NULL){
else{
while(temp!=NULL){
temp=temp->next;
int main() {
int choice;
do {
printf("\nMenu:\n");
printf("6. Exit\n");
scanf("%d", &choice);
switch (choice) {
case 1:
insertionatfront();
break;
case 2:
display();
break;
case 3:
insertionatend();
break;
case 4:
deleteatfront();
break;
case 5:
deleteatend();
break;
case 6:
printf("Exiting program.\n");
break;
default:
return 0;
}
9
#include <stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
int usn;
char name[10];
};
void insertionatfront(){
scanf("%s %d",&newnode->name,&newnode->usn);
if(head==NULL){
head=newnode;
newnode->next=NULL;
newnode->prev=NULL;
else{
newnode->next=head;
newnode->prev=NULL;
head=newnode;
void insertionatend(){
scanf("%s %d",&newnode->name,&newnode->usn);
if(head==NULL){
head=newnode;
newnode->next=NULL;
newnode->prev=NULL;
else{
while(temp->next!=NULL){
temp=temp->next;
newnode->prev=temp;
temp->next=newnode;
newnode->next=NULL;
void deleteatfront(){
if(head==NULL){
else{
head=head->next;
head->prev=NULL;
free(temp);
void deleteatend(){
struct node *p,*temp=head;
if(head==NULL){
else{
while(temp->next!=NULL){
p=temp;
temp=temp->next;
p->next=NULL;
free(temp);
void display(){
if(head==NULL){
else{
while(temp!=NULL){
temp=temp->next;
int main() {
int choice;
do {
printf("\nMenu:\n");
printf("6. Exit\n");
scanf("%d",&choice);
switch (choice) {
case 1:
insertionatfront();
break;
case 2:
display();
break;
case 3:
insertionatend();
break;
case 4:
deleteatfront();
break;
case 5:
deleteatend();
break;
case 6:
printf("Exiting program.\n");
break;
default:
}
} while (choice != 6);
return 0;
}
12
#include<stdio.h>
int left=0;
int right=size-1;
int middle=(left+right)/2;
return arr[middle];
int main(){
int arr[]={1,3,5,7,9,11,13};
int size=sizeof(arr)/sizeof(arr[0]);
int middle_element=binary_search_middle_element(arr,size);
return 0;