数组模拟列表:
数组下标对应节点
data 4 10 5 6
R 2
1 2 3 4
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int N = 110; 4 int data[N],L[N],R[N]; 5 int head=1; 6 void link(int x, int y) 7 { 8 R[x] = y; 9 L[y] = x; 10 } 11 void del(int y) //删除y 12 { 13 int x = L[y], z=R[y]; 14 link(x,z); 15 } 16 void insertR(int x, int y) //把y插入x右边 17 { 18 int z = R[x]; 19 link(x,y); 20 link(y,z); 21 } 22 int main() 23 { 24 for(int i=1;i<=10;i++) 25 { 26 data[i] = i; 27 R[i]=i+1; 28 L[i]=i-1; 29 } 30 R[10] = 0; 31 32 for(int i=head;i;i=R[i]) 33 { 34 cout<<data[i]<<" "; 35 } 36 return 0; 37 }
data[1]=4;
x=R[1];
data[x]=10;
x=R[x]
data[x]=5;
标签:10,int,void,列表,link,数组,data,模拟 From: https://www.cnblogs.com/jacy1234/p/18316752