关于15桥梁课程1&2的笔记以及待做事项的梳理
1.指针所占用的空间是固定的
2.void *malloc(sizeof(int)); (这玩意耗时间,老师说通过内存池解决)
free(p);free(p); 两次free()报错,正确的做法:
if(p!=NULL){free(p);p=NULL;}
3.传值与传址的理解应转换为是否对其空间进行操作
4.函数指针:
作用:ex: 不同厂商设备函数不同,操作系统定义设备抽象 device结构体 实现函数跳转
通用形式: 返回类型 (* 函数指针变量)(形参列表)
只能指向………………
而指针函数 :返回值为指针类型
#include<stdio.h>
void fun1(int *a)
{
int i;
for(i=;i<;i++)
printf("%d\n",a[i]);
}
void fun2(int *a)
{
int i;
for(i=;i<;i++)
printf("%d\n",*a[i]);
}
void fun3(int *a,void (*f)(int *))
{
f(a);
}
int main()
{
int a[]={,,,,,,,,,};
// fun1(a);
// fun2(a);
fun3(a,fun1);
fun3(a,fun2);
return ;
}
5.数组与指针 (为何*(*(a+2)+1)有效)
int data[3][4] data的type为int (*)[4] *data的type为int* data[1]的type为 int *
data++ data=data+1*sizeof(int)//wrong
int *p;
p=data;
for(;p<data+12;p++)
{
printf("%d",*p);
}
void fun(int a[][5])
b[5]/b[]
void fun(int *a,int m,int n)
{
}//a[i][j]______________*(a+i*sizeof(n)+j)
main()
{
int data[3][3]={};
fun(data);
}
参考链接:http://blog.sina.com.cn/s/blog_6b1695860100q84k.html http://blog.sina.com.cn/s/blog_5c6f793801019t3t.html
6.单向链表相关(by myself)
#include<stdio.h>
#include<stdlib.h> typedef struct node
{
int data;
struct node *next;
}Node; Node *Creat_link(Node*,int *,int);
void Display(Node*);
Node *FindPre(Node*,int);
void Deleteone(Node*,int);
void Deletemore(Node*,int);
void Freeroom(Node*);
Node *Reserve(Node*);
void Addnode(Node*,int);
Node *Combine(Node*,Node*);
int main()
{
Node *head=NULL;
Node *head2=NULL;
Node *head3=NULL;
int a[]={,,,,,};
int b[]={,,,};
head=Creat_link(head,a,);
// head2=Creat_link(head2,b,4);
// head3=Combine(head,head2);//合并
// Display(head3);
// Deleteone(head,a[1]);//删除一个
// Display(head);
// Deletemore(head,a[2]);//可删除重复
// Display(head);
// Addnode(head,5);//增加一个节点
// Display(head);
Reserve(head);//倒序
Display(head);
Freeroom(head);
return ;
} Node *Creat_link(Node *h,int *a,int n)
{
int i;
h=(Node *)malloc(sizeof(Node)); if(h==NULL)
{printf("Not enough memory\n");} h->next=NULL;
Node *s=h;
Node *p=NULL;
for (i=n;i>;i--)
{
p=(Node *)malloc(sizeof(Node));
p->next=h->next;
h->next=p;
p->data=a[i-];
}
return h;
} void Display(Node *h)
{
Node *p=NULL;
p=h;
while(p->next!=NULL)
{
p=p->next;
printf("%d ",p->data);
}
putchar('\n');
}
void Freeroom(Node *h)
{
Node *p=h->next;
Node *tem=NULL;
h->next=NULL;
while(p!=NULL)
{
tem=p->next;
if(tem!=NULL)
{
free(tem);
tem=NULL;
}
p=tem;
}
} Node *Reserve(Node *h)
{
Node *p=NULL;
Node *pnext=NULL;
Node *q=NULL;
if(h==NULL||h->next==NULL)
return h;
p=h->next;
pnext=p->next;
p->next=NULL;
while(pnext!=NULL)
{
q=pnext->next;
pnext->next=p;
p=pnext;
pnext=q;
}
h->next=p;
return h;
}
Node *FindPre(Node *h,int n)
{
Node *p=h;
while(p->next!=NULL&&p->next->data!=n)
p=p->next;
return p;
}
void Deleteone(Node *h,int n)
{
Node *p=FindPre(h,n);
Node *temp=NULL;
if(p->next!=NULL)
{
temp=p->next;
p->next=temp->next;
if(temp!=NULL){
free(temp);
temp=NULL;
} }
else
{printf("Not find!\n");}
} void Deletemore(Node *h,int n)
{
Node *p=FindPre(h,n);
Node *q=p->next;
Node *temp=NULL;
while(q->next!=NULL&&q->next->data==n)
{
temp=q;
q=q->next;
if(temp==NULL){
free(temp);
temp=NULL;}
}
p->next=q->next;
if(q!=NULL){
free(q);
q=NULL;
}
} void Addnode(Node *h,int data)
{
Node *p=h;
Node *new=(Node *)malloc(sizeof(Node));
while(p->next!=NULL&&data>p->next->data)
{p=p->next;}
if(p->next==NULL)
{
p->next=new;
new->next=NULL;
}
else
{
new->next=p->next;
p->next=new;
}
new->data=data;
} Node *Combine(Node *h1,Node *h2)
{
Node *p=h1;
Node *q=h2;
Node *temp1,*temp2,*temp3;
Node *h3=(h1->next->data<h2->next->data)?h1:h2;
while(q->next!=NULL&&p->next!=NULL)
{
temp2=q->next;
while(q->next!=NULL&&q->next->data<=p->next->data)
q=q->next; temp1=p->next;
while(p->next!=NULL&&p->next->data<=q->next->data)
p=p->next; temp1=p->next;
p->next=temp2;
temp2=q->next;
q->next=temp1;
}
return h3;
}
8.双向链表
#include<stdio.h>
#include<stdlib.h>
typedef struct Node
{
int data;
struct Node *front;
struct Node *rear;
}BNode; void create(BNode **head1,BNode **head2)
{
int m;
scanf("%d",&m);
BNode *p=NULL,*q=*head2;
while(m>)
{
p=(BNode*)malloc(sizeof(BNode));
p->data=m;
p->front=NULL;
p->rear=NULL; if(*head1==NULL)
{
*head1=p;
*head2=p;
}
else
{
p->rear=*head1;
p->front=NULL;
(*head1)->front=p;
*head1=p;
}
scanf("%d",&m);
}
}
void display(BNode **head1)
{
BNode *h=*head1;
while(h!=NULL)
{
printf("%d ",h->data);
h=h->rear;
}
} void addnode(BNode **head,int m)//插入m
{
BNode *p=*head;
BNode *q=(BNode*)malloc(sizeof(BNode));
q->data=m;
while(p!=NULL&&p->data<m)
{
// printf("%d__",p->data);
p=p->rear;
}
if(p!=NULL)
{
q->rear=p;
q->front=p->front;
p->front->rear=q;
p->front=q;
;
}
}
int main()
{
BNode *head1=NULL,*head2=NULL;
create(&head1,&head2);
display(&head1);
addnode(&head1,);
printf("\n");
display(&head1);
return ;
}
9. 栈 队列
//链栈
#include<stdio.h>
#include<stdlib.h> typedef struct node
{
struct node *next;
int data;
}Node; typedef struct stack
{
Node *top;
}Stack; void Init(Stack *s)
{
s->top=NULL;
} void Push(Stack *s,int m)
{
Node *p=(Node *)malloc(sizeof(Node));
p->data=m;
p->next=s->top;
s->top=p;
} int Pop(Stack *s,int *m)
{
Node *p;
if(s->top==NULL)
return ; *m=s->top->data;
p=s->top;
s->top=p->next;
free(p);
return ;
}
int main()
{
int m=;
Stack *s;
Push(s,);
Push(s,);
if(Pop(s,&m));
{
printf("%d\n",m);
}
getch();
return ;
}
#include<stdio.h>//栈
#include<stdlib.h> typedef struct node
{
int top;
int data[];
}Stack; void Init(Stack *s)
{
s->top=-;
} int Push(Stack *s,int m)
{
if(s->top>=) return ;
s->data[++(s->top)]=m;
return ;
} int Pop(Stack *s,int *m)
{ if(s->top==-) return ;
*m=s->data[s->top--];
return ;
}
int main()
{
int m=;
Stack *s;
Init(s);
Push(s,);
Push(s,);
if(Pop(s,&m));
{
printf("+++%d+++\n",m);
}
if(Pop(s,&m));
{
printf("+++%d+++\n",m);
}
getch();
return ;
}
10.通用链表
11.二叉树的遍历(递归与非递归)
#include<stdio.h>
#include<stdlib.h>
typedef struct BTNode
{
int data;
struct BTNode *Lchild;
struct BTNode *Rchild;
} BTNode; BTNode *CreateTree()//以递归的方式创建
{
int data;
BTNode *T; printf("Please input a data.");
scanf(" %d",&data);
if(data=='#')
T=NULL;
else
{
BTNode *P=(BTNode*)malloc(sizeof(BTNode));
P->data=data;
P->Rchild=CreateTree();
P->Lchild=CreateTree();
}
return T;
}
void Preorder(BTNode *T)//递归方式的前序遍历
{
if(T!=NULL)
{
printf("%d ",T->data);
Preorder(T->Lchild);
Preorder(T->Rchild);
}
} int main()
{
BTNode *T=NULL;
T=CreateTree();
Preorder(T); return ;
}
12.make file
参考链接:跟我一起写makefile http://blog.csdn.net/liang13664759/article/details/1771246
13.静态库 动态库
参考资料:http://blog.chinaunix.net/uid-23069658-id-3142046.html
14.哈希表
关于15桥梁课程1&2的笔记以及待做事项的梳理的更多相关文章
- QML学习笔记(五)— 做一个简单的待做事项列表
做一个简单的QML待做事项列表,能够动态添加和删除和编辑数据 GitHub:八至 作者:狐狸家的鱼 本文链接:QML学习笔记(五)— 做一个待做事项列表 主要用到QML:ListView 效果 全部代 ...
- Hadoop学习笔记(8) ——实战 做个倒排索引
Hadoop学习笔记(8) ——实战 做个倒排索引 倒排索引是文档检索系统中最常用数据结构.根据单词反过来查在文档中出现的频率,而不是根据文档来,所以称倒排索引(Inverted Index).结构如 ...
- php课程 9-33 php文件操作里面的注意事项有哪些
php课程 9-33 php文件操作里面的注意事项有哪些 一.总结 一句话总结:文件操作其实很简单,就是几个文件操作函数需要记一下. 1.文件函数如何使用(如何找php文件函数的资料)? 查看参考手册 ...
- 斯坦福经典AI课程CS 221官方笔记来了!机器学习模型、贝叶斯网络等重点速查...
[导读]斯坦福大学的人工智能课程"CS 221"至今仍然是人工智能学习课程的经典之一.为了方便广大不能亲临现场听讲的同学,课程官方推出了课程笔记CheatSheet,涵盖4大类模型 ...
- <<Python基础课程>>学习笔记 | 文章13章 | 数据库支持
备注:本章介绍了比较简单,只是比较使用样品,主要假设是把握连接,利用数据库.和SQLite做演示样本 ------ Python数据库API 为了解决Python中各种数据库模块间的兼容问题,如今已经 ...
- TensorFlow入门实操课程第一章练习笔记
在本练习中,您将尝试构建一个神经网络,让它根据一个简单的公式来预测房屋的价格. 想象一下,如果房子的定价很简单,带一间卧室的房子价格是5万+5万,那么一间卧室的房子要花10万元:两间卧室的房子就要花1 ...
- 斯坦福NG机器学习课程:Anomaly Detection笔记
Anomaly Detection Problem motivation: 首先描写叙述异常检測的样例:飞机发动机异常检測 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkb ...
- cocos代码研究(15)Widget子类CheckBox学习笔记
理论基础 复选框是一种特定类型的“两状态”按钮,可以处于“选中”和“未选中状态”.继承自AbstractCheckButton.注 AbstractCheckButton继承自Widget类. 代码部 ...
- [2017.02.15] 《C++Primer5》 复习笔记
编程语言主要是提供一个框架,用计算机能够处理的方式来表达问题的解决方法. 自定义数据类型class的基本思想是数据抽象dataabstraction和封装encapsulation.数据抽象是一种依赖 ...
随机推荐
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) E. Tree Folding
地址:http://codeforces.com/contest/765/problem/E 题目: E. Tree Folding time limit per test 2 seconds mem ...
- $微信小程序开发实践点滴——Bmob基本REST API的python封装
Refer:Bmob后端云REST API接口文档:http://docs.bmob.cn/data/Restful/a_faststart/doc/index.html 本文使用python对Bmo ...
- js实现删除弹框确认
JSP页面代码如下: <%@ page language="java" contentType="text/html; charset=UTF-8"%&g ...
- @RequestBody和@ResponseBody的使用情形以及RestTemplate的http报文转换
@RequestBody和@ResponseBody两个注解,分别完成请求报文到对象和对象到响应报文的转换. @RequestBody 1.@requestBody注解常用来处理content-typ ...
- 【JavaScript】下大雪
引用[JavaScript]满天星的代码,稍作修改的结果: function drawStars() { for (i = 1; i < 100; ++i) { ctx.fillText(&qu ...
- 《Language Implementation Patterns》之 语言翻译器
语言翻译器可以从一种计算机语言翻译成另外一种语言,比如一种DSL的标量乘法axb翻译成java就变成a*b:如果DSL里面有矩阵运算,就需要翻译成for循环.翻译器需要完全理解输入语言的所有结构,并选 ...
- TCP的握手与挥手
轻轻的TCP走了,正如TCP轻轻的来,TCP挥一挥手,传递了不知多少信息 看到哪,记到哪,想起哪,就看哪,这就是我的博客园,很随性 ---------------------------------- ...
- Windows 修改个性化时间显示
A goal is a dream with a deadline. Much effort, much prosperity. 我感觉我的时间显示不够人性化.不够个性化 修改注册表 我的系统为Win ...
- Routing in ASP.NET Web API
Why is HttpGet required only for some actions? https://stackoverflow.com/questions/28068868/why-is-h ...
- jQuery的序列化元素 serialize()方法 serializeArray()方法 param()方法
当提交的表单元素较多时用serialize()方法,serialize()方法也是作用于一个jQuery的对象,它能够将DOM元素内容序列化为字符串,用于Ajax请求. serialize() 方法通 ...