Question

In: Computer Science

/*instructions: please do not change the general structure of the code that I already have please...

/*instructions: please do not change the general structure of the code that I already have

please write it in C programming

Define the interface for a queue ADT and implement it in two ways: one with a dummy node (or nodes) and one without.
In addition to the two standard queue functions you’ll need a function to create/initialize an empty queue,
a function to free an existing queue (which may not be empty),
and a function to return the size (number of keys) in the queue.
All functions should be as efficient as possible, e.g., the complexity of enqueue and dequeue must be O(1).
An additional requirement is that the underlying data structure should not be a doubly-linked list.*/

#include <stdio.h>
#include <stdlib.h>

typedef struct node{
int num;
struct node *next;
}Node;

typedef struct{
Node* front
Node* rear;
int size;
}Queue;

//Define the interface for a queue ADT
Queque* initializeQueque()
{
  
}

Queque* insert(int item)
{
  
}

Queque* delete()
{
  
}

void printList(Node* Q)
{
  
}

//get the size of the queque at postion [-1]
//return the size (number of keys) in the queue.
int getsize(Node* Q)
{
  
}

int main()
{
int option,item;
Node* Queque;
  
while(1){
printf("1.Insert number to queque\n2.Delete number from queque\n3.Display numbers in queque\n4.Exit\nEnter a option:");
scanf("%d",&option);
  
switch(option){
case 1:
printf("Enter the number:");
scanf("%d",&item);
Queque=insert(item);
break;
case 2:
Queque=delete();
break;
case 3:
printList(Queque);
break;
case 4:
return 1;
default:
printf("\nWrong input!\n");
break;
}
}
}

Solutions

Expert Solution

#include <stdio.h>
#include <stdlib.h>

typedef struct node{
int num;
struct node *next;
}Node;

typedef struct{
Node* front;
Node* rear;
int size;
}Queue;

//Define the interface for a queue ADT
Queue* initializeQueque()
{
Queue* q = (Queue*)malloc(sizeof(Queue));
q->rear=NULL;
q->front=NULL;
q->size=0;
  
}

Queue* insert(Queue*q,int item)
{
Node* newnode = (Node*)malloc(sizeof(Node));
newnode->num = item;
newnode->next=NULL;
if(q->rear==NULL){
   q->rear=newnode;
   q->front = q->rear;
}
else{
   q->rear->next = newnode;
   q->rear = newnode;
}
q->size+=1;
return q;
}

Queue* delete_(Queue*q)
{Node*temp = q->front;
if(q->front==q->rear){
   q->front=NULL;
   q->rear=NULL;
}
else{
   q->front=q->front->next;
}
printf("%d is deleted\n",temp->num);
q->size-=1;
free(temp);
}

void printList(Queue* Q)
{
Node*temp=Q->front;
while(temp){
   printf("%d ",temp->num);
   temp=temp->next;
}
}

//get the size of the queque at postion [-1]
//return the size (number of keys) in the queue.
int getsize(Queue* Q)
{
return Q->size;
}

int main()
{
int option,item;
Queue* q= initializeQueque();
  
while(1){
printf("1.Insert number to queque\n2.Delete number from queque\n3.Display numbers in queque\n4.Exit\nEnter a option:");
scanf("%d",&option);
  
switch(option){
case 1:
printf("Enter the number:");
scanf("%d",&item);
q=insert(q,item);
break;
case 2:
delete_(q);
break;
case 3:
printList(q);
break;
case 4:
return 1;
default:
printf("\nWrong input!\n");
break;
}
}
}


Related Solutions

I need to take the code i already have and change it to have at least...
I need to take the code i already have and change it to have at least one function in it. it has to include one function and one loop. I already have the loop but cant figure out how to add a function. I thought i could create a funciton to call to the totalCost but not sure how to do it. Help please. #include #include //main function int main(void) {    char userName [20];    char yesOrNo [10];   ...
PLEASE I HAVE TO RETURN IN 20 MINUTES, I HAVE ALREADY DO THE QUESTION 1, 2,...
PLEASE I HAVE TO RETURN IN 20 MINUTES, I HAVE ALREADY DO THE QUESTION 1, 2, 3, 4 BUT THE QUESTION 5 I CAN'T In python : 1)Write a sum function expecting an array of integers and returning its sum. 2) Write a multiply function excepting two arrays of integers and returning the product array term by term. For example mutliply([1,2,3], [5,4,3]) will give [5,8,9] 3) Write a nb1 function expecting an array containing only 0 and 1 and returning...
This code has to be in java (I code in eclipse). Also these instructions have to...
This code has to be in java (I code in eclipse). Also these instructions have to be followed exactly because if not my output won't match the expected out ( this will be uploaded on zybooks). Write a program that asks the user for their age in days. The program will compute the person's age in years (you can assume that all years have 365 days) and then prints one of the following messages: If the user is 1 year...
Can someone please explain how to do the steps for this? I already have part a...
Can someone please explain how to do the steps for this? I already have part a completed but I need help with b-e. Thank you. Problem 1: (a) What is spurious regression? Explain. (b) Assuming , randomly generate 1000 observations of variables X and Y using the following equations: Report the graphs of X and Y. (c) Run the regression: and report the estimated results. (d) What did you expect about the magnitudes and R-square? How are the estimated values...
Use R to do each of the following. Use R code instructions that are as general...
Use R to do each of the following. Use R code instructions that are as general as possible, and also as efficient as possible. Use the Quick-R website for help on finding commands. 1. The following is a random sample of CT scores selected from 32 Miami students. 28, 27, 29, 27, 29, 31, 32, 30, 34, 30, 27, 25, 30, 32, 35, 32 23, 26, 27, 33, 33, 33, 31, 25, 28, 34, 30, 33, 28, 26, 30, 28...
I already have the code of this program, I just want to know how to fix...
I already have the code of this program, I just want to know how to fix the code to Implement the 5th function (System.nanotime() and System.currentTimeMillis() methods) What Code does: Introduction Searching is a fundamental operation of computer applications and can be performed using either the inefficient linear search algorithm with a time complexity of O (n) or by using the more efficient binary search algorithm with a time complexity of O (log n). Task Requirements In this lab, you...
INSTRUCTIONS: I HAVE ALREADY ANSWERED QUESTION 1 AND 2. I NEED ASSISTANCE WITH QUESTIONS 3 AND...
INSTRUCTIONS: I HAVE ALREADY ANSWERED QUESTION 1 AND 2. I NEED ASSISTANCE WITH QUESTIONS 3 AND 4. I HAVE FILLED OUT THE PERCENTAGE CHANGE FOR QUESTION 3, AND NEED HELP ON CALCULATING THE OPERATING, INVESTING, AND FINANCIAL SECTIONS. AS WELL AS, THE EQUATIONS FOR QUESTION 4. IF YOU CAN ANSWER QUESTIONS 3 & 4 I WILL AWARD CREDIT. Question 1: Common size for income statement Income Statement (Common Size) :                                                                  Consolidated Income Statement 2011 % 2010 % Revenue $19,176.1...
**New code needed! Please do not reference code that has already been answered for this question...
**New code needed! Please do not reference code that has already been answered for this question as that code contains errors*** Write a C++ program to simulate a service desk. This service desk should be able to service customers that can have one of three different priorities (high, medium, and low). The duration for any customer is a random number (between 5 minutes and 8 minutes). You need to write a program that will do the following: Generate random 100...
I can’t get my code to work and/or finish it. Please fix. Below are code instructions...
I can’t get my code to work and/or finish it. Please fix. Below are code instructions and then sample runs and lastly my code so far. //********************************************************************* Program You will write a program that uses a recursive function to determine whether a string is a character unit palindrome. Moreover, flags can be used to indicate whether to do case sensitive comparisons and whether to ignore spaces. For example "A nut for a jar of tuna" is a palindrome if spaces...
PLEASE DO ONLY THE "JOURNAL" SECTION. I ALREADY HAVE ANSWERS TO ALL THE OTHER ONES!!! Beacon...
PLEASE DO ONLY THE "JOURNAL" SECTION. I ALREADY HAVE ANSWERS TO ALL THE OTHER ONES!!! Beacon Signals Company maintains and repairs warning lights, such as those found on radio towers and lighthouses. Beacon Signals Company prepared the following end-ofperiod spreadsheet at December 31, 2019, fiscal year: Beacon Signals Company End-of-Period Spreadsheet For the Year Ended December 31, 2019 Unadjusted Trial Balance Adjustments Adjusted Trial Balance Account Title Dr. Cr. Dr. Cr. Dr. Cr. Cash 13,000.00 13,000.00 Accounts Receivable 40,500.00 (a)...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT