寒假集训第二天——线性表
2014-01-15 01:34
309 查看
现在时间是北京时间1点23分,第二天集训。。。
昨天花了老长时间把线性表看了下,表示很有压力,不大会用。。。
先说下我学到的线性表的皮毛。。。
首先是链表的构建,构建有两种方式:
顺序链表(尾插法建单链表)
尾插法的另一种实现方法
逆序链表(头插法建单链表)
今天可是很艰难的一天,也是很有激情的一天,链表不大会呀,想想明天还得栈与队列。。。
学了好多东西。。。
昨天花了老长时间把线性表看了下,表示很有压力,不大会用。。。
先说下我学到的线性表的皮毛。。。
首先是链表的构建,构建有两种方式:
顺序链表(尾插法建单链表)
#include<stdio.h> struct node{ int date; struct node *next; }; int main() { int i,n; node *head=new node; head->next=NULL; node *tail=head; scanf("%d",&n); for(i=0;i<n;i++) { node *p=new node; scanf("%d",&p->date);//对p构建 p->next=NULL; tail->next=p; tail=p; } for(node *p=head->next;p!=NULL;p=p->next) printf("%d ",p->date); }
尾插法的另一种实现方法
#include<stdio.h> struct node { int date; struct node *next; }; int main() { int n,i; node *head=NULL; node *tail; scanf("%d",&n); for(i=1;i<=n;i++) { node *p=new node; if(head==NULL) head=p; else tail->next=p; p->date=i;//对p构建 p->next=NULL; tail=p; } node *p; p=head; while(p!=NULL) { printf("%d ",p->date); p=p->next; } }
逆序链表(头插法建单链表)
#include<stdio.h> struct node{ int date; struct node *next; }; int main() { int i,n; node *head=NULL; scanf("%d",&n); for(i=0;i<n;i++) { node *p=new node; scanf("%d",&p->date); p->next=head; head=p; } for(node *p=head;p!=NULL;p=p->next) printf("%d ",p->date); }
今天可是很艰难的一天,也是很有激情的一天,链表不大会呀,想想明天还得栈与队列。。。
学了好多东西。。。
相关文章推荐
- C数据结构之单链表详细示例分析
- C++中单链表的建立与基本操作
- 深入单链表的快速排序详解
- java实现单链表中是否有环的方法详解
- 结构之美:定义一个线性表
- 结构之美:线性表的查找、插入与删除操作
- 线性表的概念、结构与基本操作
- 结构之美:线性表的链式存储结构——链表
- 线性表的几个链式储存结构介绍
- 结构之美:在单链表指定位置插入数据
- 《编程之美》3.4:没有头结点的单链表如何删除结点
- 结构之美:使用尾插法创建单链表
- 单链表实现
- 单链表的实现及其操作
- 判断单链表是否有环
- 单链表建环,无环链表变有环
- 用头插法实现单链表整表创建
- 单链表的删除某个元素的操作
- 单链表的插入与遍历操作
- 第03话:线性表的顺序存储结构