回复 4楼 embed_xuel
#include<stdio.h>
#include<malloc.h>
typedef int DataType ;
typedef struct Node
{
DataType data ;
struct Node *next ;
}SLNode ;
void Initiate(SLNode **head)
{
*head = (SLNode *)malloc(sizeof(SLNode)) ;
(*head) ->next = NULL ;
}
void Insert(SLNode *head , int i , DataType x)
{
SLNode *p = head , *q ;
int j = -1 ;
while (p->next != NULL && j < i - 1)
{
p = p ->next ;
j ++ ;
}
q = (SLNode *)malloc(sizeof(SLNode)) ;
q ->data = x ;
q ->next = p ->next ;
p ->next = q ;
}
void DoSomeThing(SLNode *L)
{
SLNode *Q , *P , *S = L -> next ;
if(S != NULL && S ->next != NULL)
{
Q = S ;
S = S ->next ;
P = S ;
while (P ->next != NULL)
P = P ->next ;
L->next = Q ->next ;
P ->next = Q ;
Q ->next = NULL ;
}
}
int Get(SLNode *head , int i , DataType *x)
{
SLNode *p = head ;
int j = -1 ;
while (p ->next != NULL && j < i)
{
p = p ->next ;
j ++ ;
}
*x = p ->data ;
return 1 ;
}
int main()
{
SLNode *s ;
int i , x;
Initiate(&s) ;
for(i = 0 ; i < 10 ; i ++)
Insert(s , i , i + 1) ;
DoSomeThing(s) ;
for(i = 0 ; i < 10 ; i ++)
{
Get(s , i , &x) ;
printf("%d
" , x ) ;
}
printf("\n") ;
return 0 ;
}
我最后懂了,还得谢谢你