资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

c语言中pop函数 c语言pop函数参数

“c语言”中,“pop函数”和“push函数”的作用分别是什么?

这个算是数据结构的内容讲解的是一个叫做栈类型的数据结构,这个数据结构的特点就是后进先出--最后放进去的数据最先拿出来。pop函数就是拿出数据的操作,push是放入是数据的操作。

成都创新互联主要从事成都做网站、网站建设、外贸营销网站建设、网页设计、企业做网站、公司建网站等业务。立足成都服务呼伦贝尔,10多年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18982081108

内容拓展:

pop函数呵push函数的使用:

#include stdio.h

#include unistd.h

#include pthread.h

void *clean(void *arg)

{

printf("cleanup: %s \n",(char *)arg);

return (void *)0;

}

void * thr_fn1(void * arg)

{

printf("chread 1 start \n");

pthread_cleanup_push((void *)clean,"thraed 1 first handler");

pthread_cleanup_push((void *)clean,"thread 1 second handler");

printf("thread 1 push complete \n");

if(arg)

{

return ((void *)1);

}

pthread_cleanup_pop(0);

pthread_cleanup_pop(0);

return (void *)1;

}

//输出结果: chread 1 start -thread 1 push complte 

//push和pop框起来的代码,不管正常退出还是异常退出,都将执行清除函数,但是存在特例:不包括return 退出。

C语言写Pop函数取栈的出错

Pop函数改成这样:

int Pop (Stack * pstack, int * pname)

{

if(pstack-top=0)

{

return 0;

}

pstack-top--;

* pname = pstack-data[pstack-top];

return 1;

}

Push函数改成这样:

int Push (Stack * pstack, int num)

{

if(pstack-top=Stack_size)

{

printf("Push Error!");

return 0;

}

pstack-data[pstack-top]=num;

pstack-top++;

return 0;

}

试试(原来那样当元素达到最大数目时pstack-top就越界了)。

C语言 push和pop函数可以直接用吗?

#include stdio.h

#include stdlib.h

#define MAXSIZE 32

typedef struct{

int *elem;/* 栈的存储区 */

  int max;   /* 栈的容量,即找中最多能存放的元素个数 */

  int top;   /* 栈顶指针 */ 

}Stack;

int InitStack(Stack *S, int n) /*创建容量为n的空栈*/

{

S-elem = (int *)malloc(n * sizeof(int));

if(S-elem==NULL) return -1;

S-max=n;

S-top =0; //栈顶初值0

return 0;

}

int Push(Stack *S, int item) /*将整数item压入栈顶*/

{

if(S-top==S-max) {

printf("Stack is full! \n");

return -1;

}

S-elem[S-top++] = item; //压栈,栈顶加1

return 0;

}

int StackEmpty(Stack S)

{

return (!S.top)?1:0; /*判断栈是否为空*/

}

int Pop(Stack *S) /*栈顶元素出栈*/

{

if(!S-top) {

printf("Pop an empty stack!\n");

return -1;

}

return S-elem[--S-top]  ; //弹出栈,栈顶减1

}

void MultibaseOutput(long n,int B)

{

int m; Stack S;

if(InitStack(S,MAXSIZE)){

printf("Failure!\n");

return;

}

do {

if (Push(S,B )) //------

{

printf("Failure!\n");

return;

}

n= n-1 ; //--------

}while(n!=0);

while(!StackEmpty(S)) { /*输出B进制的数*/

m=Pop(S);

if(m10) printf("%d",m); /*小于10,输出数字*/

else printf("%c", m+55); /*大于或等于10,输出相应的字符*/

}

printf("\n");

}


网页题目:c语言中pop函数 c语言pop函数参数
标题链接:http://cdkjz.cn/article/hpgsgd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220