反转链表的题目,我想用指针数组实现,但是失败了,但是错哪了?
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* struct ListNode *next;
* };
*/
struct ListNode* reverseList(struct ListNode* head){
if(head==NULL)
return head;
struct ListNode* cout[6000];
int i=0;
struct ListNode* p=head;
struct ListNode* wei=NULL;
while(p->next!=NULL)
{
cout[i]=p;
i++;
p=p->next;
}
wei=p;
i=i-1;
while(i>=0)
{
p->next=cout[i--];
p=p->next;
}
return wei;
}