关于链表
  • 板块学术版
  • 楼主125125A
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/11/10 17:18
  • 上次更新2024/11/10 20:02:07
查看原帖
关于链表
1038444
125125A楼主2024/11/10 17:18

本蒟蒻打了一个链表插入的程序,但有一些些问题,望大佬帮改一下

# 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;
} 
2024/11/10 17:18
加载中...