构建了一个有头结点的链表,输出的时候 只输出了头结点和最后一个节点的内容
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define wen "C:\Users\123\Desktop\WYT.txt"
typedef struct link {
struct link* before;
int cont;
int num;
struct link* next;
}Link;
void add1(Link* tail, int cont, int num);
int main() {
Link* head;
Link* tail;
head =(Link*) malloc(sizeof(Link));
tail = head;
int a, b;
scanf_s("%d %d", &a, &b);
while (a != -1) {
add1(tail, a, b);
scanf_s("%d %d", &a, &b);
}
while (head != NULL)
{
printf("%d %d", head->cont, head->num);
head = head->next;
}
}
void add1(Link* tail, int cont, int num) {
Link* p;
p = (Link*)malloc(sizeof(Link));
p->cont = cont;
p->num = num;
p->next = NULL;
tail->next = p;
tail = tail->next;
}