本蒟蒻打了一个链表插入的程序,但有一些些问题,望大佬帮改一下
# include <bits/stdc++.h>
using namespace std;
typedef struct Node {
int value;
Node* next;
}Node;
Node* App(){
Node* node = (Node*)malloc(sizeof(Node));
if (node == NULL) return NULL;
node->next = NULL;
node->value = 0;
return node;
}
void insertNode(Node *p, int i) {
Node *node = App();
node->value = i;
node->next = p->next;
p->next = node;
}
void Print(Node* node){
while (node != NULL){
printf ("%d -> ", node->value);
node = node->next;
}
printf ("NULL");
}
int main (){
Node* Head = App();
int m;
while (true){
scanf ("%d", &m);
if (m != -1) break;
insertNode (Head, m);
}
Print (Head);
return 0;
}