×
数据结构教程数据结构简介数据结构算法数据结构渐近分析指针结构体

数组

数组二维数组

链表

链表双链表循环单向链表循环双向链表

堆栈

堆栈数组实现堆栈堆栈的链表实现

队列

队列队列的数组实现队列的链表实现循环队列

二叉树二叉搜索树平衡搜索树(AVL树)B树B+树

图类型图的表示广度优先搜索(BFS)算法深度优先搜索(DFS)算法生成树

搜索

线性搜索二进制(二分查找)搜索

排序

冒泡排序桶排序梳排序计数排序堆排序插入排序合并排序快速排序基数(Radix)排序选择排序希尔排序双调排序鸡尾酒排序圈排序

结构体


结构是一种复合数据类型,它定义了一组变量列表,这些变量将放在一个内存块中的一个名称下。 它允许通过使用指向结构的一个指针来访问不同的变量。

struct structure_name   
{  
    data_type member1;  
    data_type member2;  
    ...  
    ...
    data_type memeber;  
};

结构体优点

  • 可以保存不同数据类型的变量。
  • 可以创建包含不同类型属性的对象。
  • 允许跨程序重用数据布局。
  • 用于实现其他数据结构,如链表,堆栈,队列,树,图等。

示例程序

#include<stdio.h>  
#include<conio.h>  
void main( )  
{  
struct employee  
{  
    int id ;  
    float salary ;  
    int mobile ;  
};
// 定义结构体变量
    struct employee e1,e2,e3 ;  
    clrscr();  
    printf ("nEnter ids, salary & mobile no. of 3 employeen"  
    scanf ("%d %f %d", &e1.id, &e1.salary, &e1.mobile);  
    scanf ("%d%f %d", &e2.id, &e2.salary, &e2.mobile);  
    scanf ("%d %f %d", &e3.id, &e3.salary, &e3.mobile);  
    printf ("n Entered Result ");  
    printf ("n%d %f %d", e1.id, e1.salary, e1.mobile);  
    printf ("n%d%f %d", e2.id, e2.salary, e2.mobile);  
    printf ("n%d %f %d", e3.id, e3.salary, e3.mobile);  
    getch();  
}

分类导航

关注微信下载离线手册

bootwiki移动版 bootwiki
(群号:472910771)