当前位置: 代码迷 >> 综合 >> PAT关于链表的知识点
  详细解决方案

PAT关于链表的知识点

热度:47   发布时间:2024-02-28 01:38:20.0

尾插法建立建表

typedef struct node {int value;struct node* next;
}node, * Linklist;
void creatlist(Linklist &l)
{Linklist tp;Linklist lst;l = NULL;l = (Linklist)malloc(sizeof(node));lst = l;int a;while (cin >> a && a > 0){tp = (Linklist)malloc(sizeof(node));tp->value = a;lst->next = tp;lst = tp;}lst->next = NULL;
}

头插法建立链表

typedef struct node {int value;struct node* next;
}node, * List;
void creatlist(List& L)
{List p;int tp;L = (List)malloc(sizeof(node));L->next = NULL;while (cin >> tp && tp >= 0){p = (node *)malloc(sizeof(node));p->value = tp;p->next = L->next;L->next = p;len++;}
}

 

相关题目

  相关解决方案