ยินดีต้อนรับคุณ, บุคคลทั่วไป กรุณา เข้าสู่ระบบ หรือ ลงทะเบียน

เข้าสู่ระบบด้วยชื่อผู้ใช้ รหัสผ่าน และระยะเวลาในเซสชั่น

ThaiSEOBoard.comพัฒนาเว็บไซต์Programmingช่วยหน่อยค่ะ[Queue] จะลบข้อมูลตำแหน่งที่ต้องการใน Queue ต้องทำไงค่ะ
หน้า: [1]   ลงล่าง
พิมพ์
ผู้เขียน หัวข้อ: ช่วยหน่อยค่ะ[Queue] จะลบข้อมูลตำแหน่งที่ต้องการใน Queue ต้องทำไงค่ะ  (อ่าน 874 ครั้ง)
0 สมาชิก และ 1 บุคคลทั่วไป กำลังดูหัวข้อนี้
dekmaidainon
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 4



ดูรายละเอียด
« เมื่อ: 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++;

    }
}

« แก้ไขครั้งสุดท้าย: 08 มีนาคม 2020, 18:29:44 โดย dekmaidainon » บันทึกการเข้า
ballsai
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 1



ดูรายละเอียด
« ตอบ #1 เมื่อ: 13 พฤษภาคม 2020, 01:18:27 »

ปกติแล้วหลักการของ queue จะเป็นแบบ First In First Out ครับ ถ้าอยากลบข้อมูลตำแหน่งที่ต้องการแนะนำให้ใช้ List แทนครับ
บันทึกการเข้า
dog010160
Newbie
*

พลังน้ำใจ: 0
ออฟไลน์ ออฟไลน์

กระทู้: 1



ดูรายละเอียด
« ตอบ #2 เมื่อ: 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缓存;
普通网站访客,请联系网站管理员;


บันทึกการเข้า
หน้า: [1]   ขึ้นบน
พิมพ์