单链表

来源:互联网 发布:ubuntu 17.10安装教程 编辑:程序博客网 时间:2024/05/16 15:46
#include<stdio.h>#include<stdlib.h>typedef struct node{int data;node * next;};node *l;node* create(node *l)//头插法建表{node *s;int x;l = new node;//建立头结点l->next = NULL;scanf("%d", &x);while (x != 999)//输入999结束{s = new node;s->data = x;s->next = l->next;l->next = s;scanf("%d", &x);}return l;}node * crea(node *l)//尾插法建表{int x;l = new node;//头结点node *s, *r = l;//需要一个尾指针scanf("%d", &x);while (x != 999){s = new node;s->data = x;r->next = s;r = s;scanf("%d", &x);}r->next = NULL;return l;}

0 0