数据结构与算法学习笔记——基础入门

1.1基本概念

数据结构:研究数据的存储问题,个体的存储+个体的关系存储

算法:对存储数据的操作

衡量算法的标准: 1、时间复杂度(大概程序要执行的次数,而非执行的时间)

           2、空间复杂度(算法执行过程中大概所占用的最大内存)

           3、难易程度

           4、健壮性

注:数据结构只是对数的存储,算法才是操作

1.2 数据结构与算法基础——指针

int * p;//p是个指针变量,int *表示该p变量只能存储int类型变量的地址
地址 :内存单元的编号,从0开始的非负整数。

指针:指针就是地址,地址就是指针

指针变量:是存放内存单元地址的变量

此时*p就代表了i,*p=i,i的值变了,*p的值也变了

数组:一维数组名是个指针常量,存放的说是一维数组第一个元素的地址。
int a[5] = {1,2,3,4,5};
a[i] == *(a+i);
a[3]== *(a+3); (注:3[a]的形式也是可以的)

结构体:类似于java中的类只是结构体中的方法
#include 
#include 
struct Student
{
  int sid;
  int age;
};

struct Student * createStudent(void);
void showStudent(struct Student *);

int main(void)
{
  struct Student * ps;
  ps = createStudent();
  showStudent(ps);	
}

struct Student * createStudent(void)
{
	struct Student * p = (struct Student *)malloc(sizeof(struct Student));//malloc动态分配内存
	p ->sid = 10; //等价于 (*p).sid=10
    (*p).age=100;
}

void showStudent(struct Student * ps)
{
	printf("%d %d\n",ps->sid,ps->age);
}




  




你可能感兴趣的:(数据结构与算法)