网创优客建站品牌官网
为成都网站建设公司企业提供高品质网站建设
热线:028-86922220
成都专业网站建设公司

定制建站费用3500元

符合中小企业对网站设计、功能常规化式的企业展示型网站建设

成都品牌网站建设

品牌网站建设费用6000元

本套餐主要针对企业品牌型网站、中高端设计、前端互动体验...

成都商城网站建设

商城网站建设费用8000元

商城网站建设因基本功能的需求不同费用上面也有很大的差别...

成都微信网站建设

手机微信网站建站3000元

手机微信网站开发、微信官网、微信商城网站...

建站知识

当前位置:首页 > 建站知识

c语言push函数使用 c++中push是什么意思

求高人帮忙 一个C语言 作业 关于 入践 和 出践 的 使用函数 PUSH 和 POP 请把 图片功能全部实现

测试过了,可以运行。

公司主营业务:网站设计、成都做网站、移动网站开发等业务。帮助企业客户真正实现互联网宣传,提高企业的竞争能力。创新互联公司是一支青春激扬、勤奋敬业、活力青春激扬、勤奋敬业、活力澎湃、和谐高效的团队。公司秉承以“开放、自由、严谨、自律”为核心的企业文化,感谢他们对我们的高要求,感谢他们从不同领域给我们带来的挑战,让我们激情的团队有机会用头脑与智慧不断的给客户带来惊喜。创新互联公司推出德宏州免费做网站回馈大家。

int eval_postfix(char *exp){

while(*exp!='\0'){

if(is_number(*exp)){

int val = *exp - 48;

push(val);

}

else{

int a1 = pop();

int a2 = pop();

if(*exp=='+') push(a2+a1);

else if(*exp=='-') push(a2-a1);

else if(*exp=='*') push(a2*a1);

else if(*exp=='/') push(a2/a1);

}

exp ++;

}

return pop();

}

void push(int e){

stack[++top] = e;

}

int pop(){

return stack[top--];

}

整个程序是:

#include stdio.h

#include stdlib.h

#define MAX_SIZE 100

#define boolean unsigned char

#define true 1

#define false 0

// Global stack

int stack[MAX_SIZE];

int top = -1;

void push(int e);

int pop();

int eval_postfix(char *exp);

boolean is_number(char c);

void main ()

{

char exp[100]; // postfix expression

int result;

while(1) {

printf("\n Input postfix expression: ");

scanf("%s", exp);

result = eval_postfix(exp);

printf(" Result = %d \n\n", result);

}

}

boolean is_number(char c)

{

if (('0' = c) (c = '9'))

return true;

else

return false;

}

int eval_postfix(char *exp){

while(*exp!='\0'){

if(is_number(*exp)){

int val = *exp - 48;

push(val);

}

else{

int a1 = pop();

int a2 = pop();

if(*exp=='+') push(a2+a1);

else if(*exp=='-') push(a2-a1);

else if(*exp=='*') push(a2*a1);

else if(*exp=='/') push(a2/a1);

}

exp ++;

}

return pop();

}

void push(int e){

stack[++top] = e;

}

int pop(){

return stack[top--];

}

KEIL用C语言加入PUSH,POP

在keil C51中,直接调用库函数:

#includeintrins.h // 其中包含了对部分汇编指令的调用申明

_nop_(); // 产生一条NOP指令

_push_(acc); // 产生一条push指令

以下是intrins.h的内容

/*--------------------------------------------------------------------------

INTRINS.H

Intrinsic functions for C51.

Copyright (c) 1988-2004 Keil Elektronik GmbH and Keil Software, Inc.

All rights reserved.

--------------------------------------------------------------------------*/

#ifndef __INTRINS_H__

#define __INTRINS_H__

extern void _nop_ (void);

extern bit _testbit_ (bit);

extern unsigned char _cror_ (unsigned char, unsigned char);

extern unsigned int _iror_ (unsigned int, unsigned char);

extern unsigned long _lror_ (unsigned long, unsigned char);

extern unsigned char _crol_ (unsigned char, unsigned char);

extern unsigned int _irol_ (unsigned int, unsigned char);

extern unsigned long _lrol_ (unsigned long, unsigned char);

extern unsigned char _chkfloat_(float);

extern void _push_ (unsigned char _sfr);

extern void _pop_ (unsigned char _sfr);

#endif

怎样用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语言堆栈push,pop,destroystack,isEmpty,isFull实现

以下代码是基于C语言写的堆栈的压栈,出栈,清栈,读栈指针等方法,在Visual studio 中,可直接使用,供学习者参考学习。

#include

#include

#include

#include

#include

#include

#define MAX_SIZE 100

typedef struct Stack

{

char *data;

int size;

int top;

};

void initStack(Stack *s); //init stack

void destroyStack(Stack *s);

bool push(Stack *s,char ch);

char pop(Stack *s);

char gettop(Stack *s);

bool isEmpty(Stack *s);

bool isFull(Stack *s);

void setNull(Stack *s);

#endif

void initStack(Stack *s)

{

s-data = (char*)malloc(MAX_SIZE * sizeof(char)); //分配最大内存空间

if (!s-data)

exit(OVERFLOW); //提前终止程序

s-size = MAX_SIZE;

s-top = -1;

}

void destroyStack(Stack *s)

{

free(s-data);

}

bool push(Stack *s, char ch)

{

if ((s-top + 1) != s-size)

{

s-data[++s-top] = ch;

return true;

}

else

return false;

}

char pop(Stack *s)

{

if (s-top != -1)

return s-data[s-top--];

}

char gettop(Stack *s)

{

return s-data[s-top];

}

bool isEmpty(Stack *s)

{

if (s-top == -1)

return true;

else

return false;

}

bool isFull(Stack *s)

{

if ((s-top + 1) == s-size)

return true;

else

return false;

}

void setNull(Stack *s)

{

s-top = -1;

}

int main()

{

char chd;

bool c;

Stack s1;

initStack(s1);

c = push(s1, 'a');

printf("Stack s1 push status is %d,s.data is %c,top value is %d ", c,s1.data[s1.top],s1.top);

c = push(s1, 'b');

printf("Stack s1 push status is %d,s.data is %c,top value is %d ", c, s1.data[s1.top], s1.top);

chd = gettop(s1);

printf("Stack s1-top data:%c,top value is %d ", chd, s1.top);

chd = pop(s1);

printf("Stack 弹出 data:%c,top value is %d ", chd, s1.top);

chd = pop(s1);

printf("Stack 弹出 data:%c,top value is %d ", chd, s1.top);

c = isEmpty(s1);

printf("Stack s1 c bool:%d,top value is %d ", c, s1.top);

c = isFull(s1);

printf("Stack s1 c bool:%d,top value is %d ", c, s1.top);

return 0;

}

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

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

内容拓展:

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语言 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语言push函数使用 c++中push是什么意思
网页路径:http://bjjierui.cn/article/hpdjhc.html

其他资讯