将数据从链表移动到队列[c]

将数据从链表移动到队列[c],c,linked-list,queue,C,Linked List,Queue,所以我是一个自学成才的人,我被困在这里。我想完成的是创建一个包含一些数据的链表,然后从链表中选择一个随机节点,更改一些数据,然后将其移动到队列中(队列也使用链表实现) 我也不知道如何写我的结构。这是我的结构 struct Apps{ int id; int size; char name; float xronos_eiswdou; char condition; int xronos_ekteleshs; struct Apps *nex

所以我是一个自学成才的人,我被困在这里。我想完成的是创建一个包含一些数据的链表,然后从链表中选择一个随机节点,更改一些数据,然后将其移动到队列中(队列也使用链表实现)

我也不知道如何写我的结构。这是我的结构

struct Apps{
    int id;
    int size;
    char name;
    float xronos_eiswdou;
    char condition;
    int xronos_ekteleshs;
    struct Apps *next, *next1;
}*rear, *front;
我确信这是错误的,我不知道如何修复它

这是我现在的职责

void push(struct Apps *head)
{
     struct Apps *temp; 
     struct Apps *temp1;
     temp1=(struct Apps *)malloc(sizeof(struct Apps));
     temp1->id = temp->id;
     temp1->size = temp->size;
     temp1->name = temp->name;
     temp1->xronos_eiswdou = temp->xronos_eiswdou;
     temp1->condition = temp->condition;
     temp1->xronos_ekteleshs = temp->xronos_ekteleshs;
     temp1->next = head;
     if (front == NULL)
     {
           front=temp1;
           front->next1=NULL;
           rear=front;
     }
     else
     {
           front->next1=temp1;
           front=temp1;
           front->next1=NULL;
     }
}
以下是我将数据添加到链接列表的主要代码:

for(step = 0; step < 100; step++)
      {
        int r = rand() % 100+1;
        if(r < 31){
            int r1 = rand() % 100+1;
            aa = r1;
            int r2 = rand() % 100+1;
            bb = r2;
            int r3 = rand() % 3;
            if(r3 == 0){ 
                 cc = 'l';
            }
            else if(r3 == 1 ){ 
                 cc = 'b';
            }
            else if( r3 == 2 ){ 
                 cc = 'c';
            }
            dd = (double)seconds/CLOCKS_PER_SEC;
            ee = 'a';
            ff = -1;
            insert_new(aa, bb, cc, dd, ee, ff);
        }
        else if(r > 30 && r < 51){
            pickRandom(head); /*picking a random node and changing some data*/
            /*Here I need a function which moves the data of the above node to a queue*/
        }
    }
这是我的功能:

struct Queue *start = NULL;
struct Queue *front = NULL;
struct Queue *rear = NULL;

    void push()
    {
         struct Apps *temp; 
         struct Queue *temp1;
         temp1=(struct Queue *)malloc(sizeof(struct Queue));
         temp1->id1 = temp->id; 
         temp1->size1 = temp->size;
         temp1->name1 = temp->name;
         temp1->xronos_eiswdou1 = temp->xronos_eiswdou;
         temp1->condition1 = temp->condition;
         temp1->xronos_ekteleshs1 = temp->xronos_ekteleshs;
         temp1->next = start;
         if (front == NULL)
         {
               front=temp1;
               front->next=NULL;
               rear=front;
         }
         else
         {
               front->next=temp1;
               front=temp1;
               front->next=NULL;
         }
}
程序运行时没有错误,但是崩溃了,所以又出了问题

所以你的问题是

1.列表包含一些随机数目的节点

2.必须在队列(另一个列表)中收集列表中修改的元素

要解决此问题,请将您的结构修改为:

 struct Apps{
    int id;
    int size;
    char name;
    float xronos_eiswdou;
    char condition;
    int xronos_ekteleshs;
    struct Apps *next;
};

struct Queue
{
    Struct Apps *node;
    struct Queue * next;
};
因此,现在您将在队列(queue_struct)中收集列表(应用程序)中的原始元素列表和修改的节点(应用程序列表),该队列是通过
LinkedList实现的,因此您的问题是

1.列表包含一些随机数目的节点

2.必须在队列(另一个列表)中收集列表中修改的元素

要解决此问题,请将您的结构修改为:

 struct Apps{
    int id;
    int size;
    char name;
    float xronos_eiswdou;
    char condition;
    int xronos_ekteleshs;
    struct Apps *next;
};

struct Queue
{
    Struct Apps *node;
    struct Queue * next;
};


因此,现在您将在队列(queue_struct)中收集列表(应用程序)中的原始元素列表和修改的节点(应用程序列表),该队列是用
LinkedList

实现的,与您的问题无关,但您确实应该根据其中一个标准格式化代码,例如,在C教科书中。您的代码很难阅读。首先实现删除节点的功能-您必须将列表中上一项中的
next
指针更改为已删除节点的
next
指针。完成此操作后(使用
插入
),组件就就位了。每次执行一个步骤。@cdarke我想将数据移动到队列的节点,然后从列表中删除该节点。这是我不理解的,我认为他正在尝试将类型为(应用程序)的节点移动到他的队列(队列结构)ie;他试图在队列中收集修改后的
应用程序
节点,这似乎与您的问题无关,但您确实应该按照其中一个标准格式化代码,例如,像C教科书中那样。您的代码很难阅读。首先实现删除节点的功能-您必须将列表中上一项中的
next
指针更改为已删除节点的
next
指针。完成此操作后(使用
插入
),组件就就位了。每次执行一个步骤。@cdarke我想将数据移动到队列的节点,然后从列表中删除该节点。这是我不理解的,我认为他正在尝试将类型为(应用程序)的节点移动到他的队列(队列结构)ie;他正在试图收集队列中已修改的
应用程序
节点似乎…好的,完成了。。。我的另一个问题是,我无法理解如何编写在queuesuper中移动已修改节点的函数。。那么请尝试一下,如果您在实现时遇到任何问题,请告诉我..我尝试了一些东西,但当我运行它时它崩溃了。但是没有编译错误。你能在我的问题中查看我的编辑吗?你有一个变量
temp
(struct Apps*temp;),你既没有为它分配一些内存,也没有用一些值初始化它,但你试图从中获取值,这会导致一些错误情况…好的,完成了。。。我的另一个问题是,我无法理解如何编写在queuesuper中移动已修改节点的函数。。那么请尝试一下,如果您在实现时遇到任何问题,请告诉我..我尝试了一些东西,但当我运行它时它崩溃了。但是没有编译错误。你能在我的问题中查看我的编辑吗?你有一个变量
temp
(struct Apps*temp;),你既没有为它分配一些内存,也没有用一些值初始化它,但你试图从中获取值,这会导致一些错误情况。。。