#include <stdio.h>
#include <stdlib.h>
#include <memory.h>
typedef struct a
{
int i
;
int j
;
char c
;
struct a
* pNext
;
}A
;
A
* getMemory(A
** pA
)
{
*pA
= (A
*)malloc(sizeof(A
));
return *pA
;
}
A
* insertZ(A
* pA
,int i
,int j
,char c
)
{
if (pA
!= NULL)
{
pA
->i
= i
;
pA
->j
= j
;
pA
->c
= c
;
}
return pA
;
}
A
* selectZ(A
* pA
, int i
)
{
for(int cout
= 0;cout
<=i
,pA
!= NULL;pA
= pA
->pNext
,++cout
)
{
if (cout
== i
-1)
{
printf("selectZ: %d %d %c\n\n",pA
->i
,pA
->j
,pA
->c
);
return pA
;
}
}
}
bool deleteZ(A
* pA
,int i
)
{
pA
= selectZ(pA
,i
);
pA
->pNext
= pA
->pNext
->pNext
;
return true;
}
void modyNode(A
* node
,int i
)
{
node
= selectZ(node
,i
);
node
->pNext
->i
= 9;
node
->pNext
->j
= 10;
node
->pNext
->c
= 'Z';
}
void showNode(A
* node
)
{
while(node
!= NULL)
{
printf("showNode: %d %d %c\n\n",node
->i
,node
->j
,node
->c
);
node
= node
->pNext
;
}
}
int main()
{
A
* node1
;
node1
= getMemory(&node1
);
node1
= insertZ(node1
,1,2,'a');
A
* node2
;
node2
= getMemory(&node1
->pNext
);
node2
= insertZ(node2
,3,4,'b');
A
* node3
;
node3
= getMemory(&node2
->pNext
);
node3
= insertZ(node3
,5,6,'j');
node3
->pNext
= NULL;
A
* node4
;
node4
= getMemory(&node4
);
node4
= insertZ(node4
,7,8,'k');
node4
->pNext
= NULL;
node3
->pNext
= node4
;
showNode(tmp1
);
modyNode(tmp1
,1);
showNode(tmp1
);
return 0;
}
转载请注明原文地址:https://tech.qufami.com/read-6865.html