ตามหัวข้อค่ะ พอดีอยากลบตำแหน่งที่ต้องการที่อยู่ใน Queue แต่ทำไงก้ทำไม่ได้เลยสงสัยว่าต้องทำไงค่ะ ขอคความกรุณาด้วยนะค่ะ
#include <stdio.h>
#include <stdlib.h>
#define MAX 3
int front = -1,rear = -1;
int pos;
int in[MAX];int data;
int main()
{
int choice;
printf("stack program\n");
do{
printf("\n1)Insert \n");
printf("2)Delete \n");
printf("3)Display \n");
printf("4)Size \n");
printf("5)Average \n");
printf("6)Exit \n");
printf("Enter Your Choice: ");
scanf("%d",&choice);
switch(choice){
case 1: printf("Enter data: ");
scanf("%d",&data);
insert(data);
break;
case 2:
//Delete(data);
printf("Enter position: ");
scanf("%d",&data);
posDl(data);
break;
case 3: printf("Display: ");
display(data);
printf("\n");
break;
case 4: sizeofQueue(data);
case 5: printf("average = \n",findAvg(data));
}
}while(choice!=6);
return 0;
}
void insert(int x){
if(rear==MAX-1)
{
printf("Queue is Full\n");
}
else
{
if(front==-1)
{
front = 0;
}
rear++;
in[rear]=x;
}
}
ตัวนนี้มันลบตำแหน่งแรกเสมออะ
void Delete(){
int x =-1;
if(front==-1)
{
printf("Can not dequeue, queue is Empty\n");
}else{
//for(int i=front;i=in
x = in[front];
front++;
//}
}
return x;
}
ส่วนตัวนี้เราลองเอามาปรับเลียนแบบนะค่ะ
void posDl(){
int y = -1;
if(front==-1)
{
printf("Can not dequeue, queue is Empty\n");
}else{
y = in[pos];
pos++;
}
}