小编Ras*_*ion的帖子

在链接列表C++中的某个位置插入节点

我正在尝试在某个位置插入一个节点.在我的代码中,位置1的数字仅被插入(基本上在链表的开头)并且它没有插入位置2的任何数据.是否有一些错误的temp2?当我运行程序时,它并没有指向我想的任何东西.

我知道你们有多讨厌这里被问到的家庭作业问题,但我不知道我的课程有什么问题.我只是一个初学者,我的老师没有很好地解释链表.

代码如下.

- 我得到的输出是8 7

- 我希望它读取8 6 7 5,其中6和5插入位置2

/*
Insert node at a given positon in a linked list.
First element in the linked list is at position 0
*/

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

struct Node
{
   int data;
   struct Node* next;
};

struct Node *head;

void Insert(int data, int n)
{
   Node* temp1 = new Node();
   temp1->data = data;
   temp1->next = NULL;
   if (n == 1){
    temp1->next = head;
    head = temp1;
    return;
   }
   Node* temp2 = new …
Run Code Online (Sandbox Code Playgroud)

c++ position linked-list insert nodes

5
推荐指数
2
解决办法
12万
查看次数

上标加号含义

我有一个快速的问题。这里的上标加号是什么意思?

= {w ? {0,1} : w ? (0^+)(1^+)}

自从我完成这些以来已经有一段时间了。这是用于制作非确定性有限自动机

theory automata finite-automata state-machine computation-theory

2
推荐指数
1
解决办法
3616
查看次数