成都创新互联网站制作重庆分公司

c语言empty函数 empty函数的作用

empty可以作为c语言变量名吗? do呢?

empty(空) 可以做 C 语言变量,因为它不是 C 编译器提供的关键字。但是 do 绝对不能够做 C 语言变量,因为 do 是 C 语言本身提供的关键字。类似地,其它的所有 C 语言提供的关键字,像:if、for、while、switch、case 等等,都不能够作为 C 语言的变量名。

创新互联从2013年创立,是专业互联网技术服务公司,拥有项目成都网站设计、成都做网站、外贸网站建设网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元平顶山做网站,已为上家服务,为平顶山各地企业和个人服务,联系电话:028-86922220

数据结构C语言版中 队列操作中 InitQuene(&Q) 与 QueneEmpty(Q) 加&与不加什么区别?

亲,C/C++函数的参数表有:按值传递参数,引用传递参数,指针传递参数。

QueneEmpty(Q) 是按值传递参数的,参数是会占用一部分内存的。

InitQuene(Q)是按引用传递参数的,简单理解就是引用一个变量给参数,所以参数只是引用了一下,不占内存的,参数相当于一个快捷方式,就相当于快捷方式符号吧。引用的好处一是省内存,二是可以用参数返回值,关于参数返回函数值请自行查阅测试。

还有指针的,不讲了。了解指针就好了。

简单理解,说得不一定对。

c语言中有没有清空文件的函数

fclose(fp);当然不行,它不是清除文件而是关闭文件。fp=fopen("a.txt","w");肯定清除当前目录下名为a.txt文件的内容,只留下一个文件名——你说没有清除那只是路径没有写全——我的工作代码就这样用着:每月1号0点自动清除上月记录,开始本月新记录。如果你说的是连文件名都清除的函数,那叫删除文件,有个函数叫remove(FILE *);,你可以一试。

C语言编程

/*link.cÔ´³ÌÐò*/

#include stdio.h

#include stdlib.h

#include string.h

struct student

{

int id;

char name[20];

int age;

struct student *next;

};

void Add(struct student **ps, int id, char *name, int age);

void Print(struct student *ps);

void Del(struct student **ps, int pos);

int Length(struct student *ps);

void Search(struct student *ps, int id);

void Insert(struct student **ps, int id, char *name, int age, int pos);

void Empty(struct student **ps);

int main()

{

struct student *head;

head = NULL;

//Add

Add(head, 1, "a", 18);

Add(head, 2, "b", 19);

Add(head, 3, "c", 20);

Add(head, 4, "d", 21);

//Print

Print(head);

//Del

Del(head, 2);Print(head);

//Length

printf("Length:%d\n", Length(head));

//Search

Search(head, 4);

//Insert

Insert(head, 2, "B", 22, 2);Print(head);

//Empty

Empty(head);Print(head);

return 0;

}

void Add(struct student **ps, int id, char *name, int age)

{

struct student *p, *q;

if(!ps) return;

if(!name) return;

p = (*ps);

if (p)

{

while (p-next)

{

p = p-next;

}

p-next = (struct student*)malloc(sizeof(struct student));

q = p-next;

}

else

{

(*ps) = (struct student*)malloc(sizeof(struct student));

q = (*ps);

}

if (q)

{

q-id = id;

strcpy(q-name, name);

q-age = age;

q-next = NULL;

}

else

{

printf("Not enough memory!\n");

exit(-1);

}

}

void Print(struct student *ps)

{

struct student *p = ps;

printf("%10s%10s%10s\n", "id", "name", "age");

while (p)

{

printf("%10d%10s%10d\n", p-id, p-name, p-age);

p = p-next;

}

}

void Del(struct student **ps, int pos)

{

if (!ps) return;

if (!*ps) return;

struct student *p = *ps, *q = NULL;

while (p-next != NULL pos != 0)

{

q = p;

p = p-next;

pos--;

}

if (pos)

{

return;

}

else

{

q-next = p-next;

free(p);

}

}

int Length(struct student *ps)

{

int nLen = 0;

while (ps)

{

ps = ps-next;

nLen++;

}

return nLen;

}

void Search(struct student *ps, int id)

{

while (ps)

{

if (ps-id == id)

{

printf("id:%d\tname:%s\tage:%d\n", ps-id, ps-name, ps-age);

break;

}

ps = ps-next;

}

}

void Insert(struct student **ps, int id, char *name, int age, int pos)

{

if (!ps) return;

if (!*ps) return;

struct student *p = *ps, *q = NULL;

while (p-next != NULL pos != 0)

{

q = p;

p = p-next;

pos--;

}

if (pos)

{

return;

}

else

{

p = (struct student *)malloc(sizeof(struct student));

if (p)

{

p-id = id;

strcpy(p-name, name);

p-age = age;

p-next = q-next;

q-next = p;

}

else

{

printf("Not enough memory!\n");

exit(-1);

}

}

}

void Empty(struct student **ps)

{

if (!ps) return;

if (!*ps) return;

if((*ps)-next)

{

Empty(((*ps)-next));

}

free(*ps);

(*ps) = NULL;

}

测试通过

怎样用C语言写出对栈进行的五种运算:push()、pop()、top()、empty()、makempty()

这是我用链表写的:

#include stdio.h

#include stdlib.h

typedef struct node

{

int x;

struct node *next;

}Node;

typedef struct stack

{

Node *top;

}Stack;

void InitStack(Stack *s)

{

s-top=NULL;

}

int IsEmpty(Stack *s)

{

if(s-top==NULL)

return 1;

else

return 0;

}

void PushStack(Stack *s,int x)

{

Node *p;

p=(Node*)malloc(sizeof(Node));

p-x=x;

// p-next=NULL;

p-next=s-top;

s-top=p;

}

int PopStack(Stack *s)

{

int data;

Node *p;

p=(Node *)malloc(sizeof(Node));

if(IsEmpty(s))

{

printf("the stack is empty!\n");

free(p);

return -1;

}

else

{

p=s-top;

data=p-x;

s-top=p-next;

free(p);

return data;

}

}

int main (int argc,char **argv)

{

int i;

Stack s;

InitStack(s);

for(i=0;i1000;i++)

{

PushStack(s,i);

}

for(i=0;i1000;i++)

{

printf("%d\n",PopStack(s));

}

}


网站标题:c语言empty函数 empty函数的作用
网站路径:http://cxhlcq.com/article/hpheih.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部