无法正确反向输出链表
#include <stdio.h>
#include "string.h"
#include "stdlib.h"
typedef struct node {
int data;
struct node* next;
}Node;
int main() {
struct node *newn = malloc(sizeof(struct node));
struct node *newn2 = malloc(sizeof(struct node));
newn->next = NULL;
Push(&newn, 1);
Push(&newn, 2);
Push(&newn, 3);
Push(&newn, 4);
Push(&newn, 4);
RecursiveReverse(&newn);//?
printQueue(newn);
return 0;
}
void Push(Node**headRef, int newData){
Node *head = *headRef;
struct node *newn = malloc(sizeof(struct node)); //
newn->data = newData;
newn->next = head;
head = newn;
*headRef = head;
}
void RecursiveReverse(Node**headRef){
struct node* head = (*headRef);
if(head->next->next !=NULL){
RecursiveReverse(&(head->next));
}
while(head->next !=NULL){
head = head->next;
}
struct node* newn2 = (*headRef);
(*headRef) = (*headRef)->next;
head->next = newn2;
newn2->next =NULL;
}
void printQueue(Node* l){
while(l->next != NULL){//
printf("data is %d\n", l->data);
l = l->next;
}
printf("\n");
}
推入的数据应该是1,2,3,4,4,结果应该是12344
但是这个输出的是
data is 11950480
data is 1
data is 2
data is 3
data is 4
不知道哪里出问题了