ThaiSEOBoard.com

พัฒนาเว็บไซต์ => Programming => ข้อความที่เริ่มโดย: dekmaidainon ที่ 08 มีนาคม 2020, 18:21:13



หัวข้อ: ช่วยหน่อยค่ะ[Queue] จะลบข้อมูลตำแหน่งที่ต้องการใน Queue ต้องทำไงค่ะ
เริ่มหัวข้อโดย: dekmaidainon ที่ 08 มีนาคม 2020, 18:21:13
ตามหัวข้อค่ะ พอดีอยากลบตำแหน่งที่ต้องการที่อยู่ใน 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
  • ;i++){
            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++;

    }
}



หัวข้อ: Re: ช่วยหน่อยค่ะ[Queue] จะลบข้อมูลตำแหน่งที่ต้องการใน Queue ต้องทำไงค่ะ
เริ่มหัวข้อโดย: ballsai ที่ 13 พฤษภาคม 2020, 01:18:27
ปกติแล้วหลักการของ queue จะเป็นแบบ First In First Out ครับ ถ้าอยากลบข้อมูลตำแหน่งที่ต้องการแนะนำให้ใช้ List แทนครับ


หัวข้อ: Re: ช่วยหน่อยค่ะ[Queue] จะลบข้อมูลตำแหน่งที่ต้องการใน Queue ต้องทำไงค่ะ
เริ่มหัวข้อโดย: dog010160 ที่ 13 พฤษภาคม 2020, 03:59:12
ตามหัวข้อค่ะ พอดีอยากลบตำแหน่งที่ต้องการที่อยู่ใน 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
  • ;i++){
            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[po
您的请求在

可能原因:

您没有将此域名或IP绑定到对应站点!
配置文件未生效!
如何解决:

检查是否已经绑定到对应站点,若确认已绑定,请尝试重载Web服务;
检查端口是否正确;
若您使用了CDN产品,请尝试清除CDN缓存;
普通网站访客,请联系网站管理员;