关于#c++#的问题:他想说明不声明指针而使效果等同于指针

这是课上的代码,想不使用指针而使效果等同于指针。可是我看不懂这个代码。(注:该代码是我根据课上的板书编写下来的,有可能有错,您也可以指出)
如果我的代码有很大错误,您也可以根据我的意思给出相应的代码。
【代码】

#include<bits/stdc++.h>
using namespace std;
int a[10];
int main(){
    int n;
    cin>>n;
    struct node{
        int data;
        int next;    
    }; 
    int head=0;
    struct node pool[100];
    for(int i=0;i<n;i++){
            pool[i].data=a[i];
            pool[3].data=a[i];
            pool[3].next=head;
            cout<<head;
    } 
    return 0;
}


根据您提供的代码,您似乎想在结构体数组 pool 中存储一个单链表。具体来说,您想要将数组 a 中的元素存储到 pool 数组的 data 字段中,并将 pool 数组的某个元素的 next 字段指向链表的头部。

下面是等效的代码,不使用指针实现相同的功能:

#include<bits/stdc++.h>
using namespace std;
int a[10];
int main(){
    int n;
    cin>>n;
    struct node{
        int data;
        int next;
    };
    struct node pool[100];
    for(int i=0;i<n;i++){
        pool[i].data=a[i];
        pool[i].next=i-1;
    }
    int head=n-1;
    cout<<head;
    return 0;
}

在这个代码中,我们使用了结构体数组 pool 来存储单链表。每个结构体元素包含一个 data 字段和一个 next 字段,其中 data 字段存储链表节点的值,next 字段存储下一个节点的索引。我们还定义了一个变量 head,用于存储链表的头部索引。

具体来说,我们使用循环遍历数组 a,并将数组中的元素存储到结构体数组 pool 的 data 字段中。在遍历过程中,我们使用当前元素的索引 i 来设置结构体数组 pool 中下一个元素的 next 字段。具体来说,我们将 pool[i].next 设为 i-1,这样可以将链表中的节点按照数组中的顺序连接起来。

最后,我们将 head 设为链表的最后一个元素的索引,即 n-1,并输出 head 的值。这段代码假设数组 a 的长度不超过 100,且单链表的长度不超过 n。如果 n 或 a 的长度超过了这个限制,可能会导致数组越界等错误。

就是每个链表节点不使用new分配空间,而是指向已经定义的数组空间就行了
代码有点错误,应该是:

#include<bits/stdc++.h>
using namespace std;
#define MAXSIZE 100
int a[MAXSIZE];
int main(){
    int n;
    cin>>n;
    struct node{
        int data;
        int next;    
    }; 

    struct node pool[MAXSIZE];
    int head=0;
    for(int i=0;i<n;i++){
            pool[i].data=a[i];
            if(i!=n-1)
              pool[i].next = i+1;
            else
              pool[i].next=  0;
    } 
    return 0;
}