| 
 | 
 
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册  
 
x
 
int main(){ 
 struct student *head,*p,*q,*n,*test; 
 struct student * Reverse(struct student * L); 
    int m=0; 
    p=q=(struct student *)malloc(sizeof(struct student)); 
    scanf("%d%d",&p->num,&p->score); 
    head=NULL; 
    while(p->num!=0) 
    { 
        m=m+1; 
        if(m==1) 
            head=p; 
        else{ 
        q->next=p; 
        q=p; 
        p=(struct student *)malloc(sizeof(struct student)); 
        scanf("%d%d",&p->num,&p->score); 
    }} 
    q->next=NULL; 
    test=Reverse(head); 
} 
struct student * Reverse(struct student * L){ 
    if(L==NULL) return NULL; 
    if(L->next==NULL) return L; 
 
    struct student *p,*r; 
    p=L; 
    r=p->next; 
    p->next=NULL; 
    while(r!=NULL){ 
       r->next=p; 
        p=r; 
        r=r->next; 
} 
 
return r; 
} 
- struct NODE *sll_reverse(struct NODE *first)
 
 - {
 
 -     Node *newfirst;
 
 -     Node *p = first;
 
 -     Node *q = first;
 
 -     if(first == NULL)
 
 -         return NULL;
 
  
- //让p指向最后一个元素,q指向倒数第二个
 
 -     while(p->link != NULL){
 
 -         q = p;
 
 -         p = p->link;
 
 -     }
 
 -     newfirst = p;
 
  
- //箭头反转
 
 -     while(q != first){
 
 -         p->link = q;
 
 -         p = q;
 
 -     }
 
 -     q->link = NULL;
 
 -     return newfirst;    
 
 - }
 
  复制代码 
 
 
 |   
 
 
 
 |