进入数据结构的时代

简介: 初始数据结构

                                                  第一天

1、定义顺序表存储结构

2、初始化顺序表为空(InitList_Sq)

3、输入顺序表数据(CreateList_Sq)

4、遍历(输出)顺序表数据(TraverseList_Sq)

5、销毁顺序表数据(DestroyList_Sq)

例如:

输入元素个数和数据如下:

5

5  3  8  7  9

程序输出为:

5,3,8,7,9

#include <stdio.h>
#include <stdlib.h>
#define MAXSIZE 100
typedef struct
{
    int *head;
}a;
void InitList_Sq(a t)
{
    t.head=(int*)malloc(sizeof(int));
}
void CreatList_Sq(a t,int b)
{
    int c;
    for(int i=0;i<b;i++){
        scanf("%d",&c);
        t.head[i]=c;
    }
}
void TraverseList_Sq(a t,int b){
    int k;
    for(k=0;k<b;k++){
        if(k==0){
            printf("%d",t.head[k]);
        }
        if(k!=0){
        printf(",%d",t.head[k]);
        }
    };
}
void main(){
    int b;
    scanf("%d",&b);
    a t;
    InitList_Sq(t);
    CreatList_Sq(t,b);
    TraverseList_Sq(t,b);
}

image.gif


相关文章
|
28天前
|
存储 程序员 定位技术
什么是数据结构
什么是数据结构
25 1
|
2月前
|
存储 算法 前端开发
了解数据结构
了解数据结构相关知识
|
3月前
|
算法
数据结构22
数据结构22
12 0
|
8月前
|
存储 容器
|
4月前
|
存储 算法
数据结构
数据结构
24 2
|
5月前
|
算法 Python
02 数据结构
02 数据结构
19 0
uiu
|
存储 算法 JavaScript
我对八种常见数据结构的理解(二)
我对八种常见数据结构的理解(二)
uiu
153 0
我对八种常见数据结构的理解(二)
|
存储 索引
常见的数据结构
常见的数据结构
113 0
常见的数据结构
|
存储 算法 数据可视化
数据结构大总结!
而所谓数据结构,是数据的组织、管理和存储格式。简单理解的话,数据结构就是执行算法的“原材料”。
303 0
|
存储 C++
【第二讲】数据结构(3)
【第二讲】数据结构(3)