当前位置:首页 » 编程语言 » c语言pop

c语言pop

发布时间: 2022-07-12 08:28:49

c语言,pop函数和push函数的作用分别是什么请详细一点,谢谢。我是初学者~

pop函数 出栈 ;push函数 进栈。
相当于有一个箱子,push函数是把东西放进去;而pop函数则相反,是把东西从那箱子里拿出来。

⑵ C语言中的pop函数是什么单词的缩写

关于 pop 函数,我不太确定题主说的是哪个函数,因为 C 语言的标准函数库是没有 pop 这个函数的。如果题主说的是 C++ 的 Stack 类中的 pop 函数的话,它并不是一个缩写,因为从栈中取值的操作就叫做 pop。


然后就是查询单词原型的网站,因为 C 语言好多函数库中的函数名都是按照很奇怪的方法缩写的,所以基本上没有一个专门查全称的网站。不过题主可以参考


http://www.cplusplus.com/reference/clibrary/


这个网站里面虽然没有指出具体的缩写方式,但是能很好地解释 C 语言标准函数库的所有函数的作用。通过它的介绍你应该会对函数的全称有一个大概的理解。比如说这个针对 stdio.h 头文件中所定义函数的解释:



不光是 C 语言,C++ 的标准类库的信息也可以在这个网站中找到。

⑶ c语言 函数参数传递 int pop(int *s, int *e)

在函数定义时写int
pop(int
&s,
int
&e)是说明参数是直接引用的参数
在函数调用时写pop(&a,
&b);[注意这个不是函数定义,而是调用语句],
这里的&是取地址的运算,与函数参数定义时的&不是同一个含义,因此在这里不能理解是引用传递的意思,而是取a和b的地址传递给函数的参数变量s和e(应该是调用第3个函数)
第2个函数调用直接写pop(a,b);即可实现

⑷ C语言有类似于汇编PUSH,POP的函数么

1.这个是栈的数据结构 必须自己实现(它跟push和pop指令没有关系 可以去学习《数据结构》)

2.push和pop是指令不是函数 用嵌入汇编实现

#include<stdio.h>
intmain(void)
{
char*a="helloworld! ";
_asm{pusha}
printf("%s");
_asm{addesp,4}
return0;

}


⑸ C语言用push和pop来写单链表倒序程序

//单链表的逆序输出分为两种情况,一种是只逆序输出,实际上不逆序;另一种是把链表逆序//本文就分别实例讲述一下两种方法。具体如下:
//1.逆序输出
//实例代码如下:
#include<iostream>
#include<stack>
#include<assert.h>
usingnamespacestd;

typedefstructnode{
intdata;
node*next;
}node;

//尾部添加
node*add(intn,node*head){
node*t=newnode;
t->data=n;
t->next=NULL;
if(head==NULL){
head=t;
}
elseif(head->next==NULL){
head->next=t;
}
else{
node*p=head->next;
while(p->next!=NULL){
p=p->next;
}
p->next=t;
}
returnhead;
}

//顺序输出
voidprint(node*head){
node*p=head;
while(p!=NULL){
cout<<p->data<<"";
p=p->next;
}
cout<<endl;
}

//递归
voidreversePrint(node*p){
if(p!=NULL){
reversePrint(p->next);
cout<<p->data<<"";
}
}

//栈
voidreversePrint2(node*head){
stack<int>s;
while(head!=NULL){
s.push(head->data);
head=head->next;
}

while(!s.empty()){
cout<<s.top()<<"";
s.pop();
}
}

intmain(){

node*head=NULL;
for(inti=1;i<=5;i++){
head=add(i,head);
}
print(head);
reversePrint(head);
reversePrint2(head);
system("pause");
return0;
}
//2.单链表逆序
//实例代码如下:
#include<iostream>
#include<stack>
#include<assert.h>
usingnamespacestd;


typedefstructnode{
intdata;
node*next;
}node;

node*add(intn,node*head){
node*t=newnode;
t->data=n;
t->next=NULL;
if(head==NULL){
head=t;
}
elseif(head->next==NULL){
head->next=t;
}
else{
node*p=head->next;
while(p->next!=NULL){
p=p->next;
}
p->next=t;
}
returnhead;
}

//循环
node*reverse(node*head){

if(head==NULL||head->next==NULL){
returnhead;
}

node*p1=head;
node*p2=head->next;
node*p3=NULL;
head->next=NULL;

while(p2!=NULL){
p3=p2;
p2=p2->next;
p3->next=p1;
p1=p3;
}
head=p1;
returnhead;
}

voidprint(node*head){
node*p=head;
while(p!=NULL){
cout<<p->data<<"";
p=p->next;
}
cout<<endl;
}


//递归
node*reverse2(node*p){
if(p==NULL||p->next==NULL){
returnp;
}

node*newHead=reverse2(p->next);
p->next->next=p;
p->next=NULL;
returnnewHead;
}


intmain(){

node*head=NULL;
for(inti=1;i<=5;i++){
head=add(i,head);
}
print(head);
head=reverse(head);
print(head);
head=reverse2(head);
print(head);

system("pause");
return0;
}

⑹ 怎样用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;i<1000;i++)
{
PushStack(&s,i);
}
for(i=0;i<1000;i++)
{
printf("%d\n",PopStack(&s));
}
}

⑺ c语言中出现函数矛盾怎么办,例如pop(s,x)用c语言编译后出现错误,这是数据结构题。

什么叫函数矛盾?
你用的是C++编译环境吗?
改成.c就行了
标准C中没有pop这个函数
如果要用C++
#include<stack>
有pop
push
数据结构的模板

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

#include<stdio.h>
#include<stdlib.h>

#defineMAXSIZE32
typedefstruct{
int*elem;/*栈的存储区*/
intmax;/*栈的容量,即找中最多能存放的元素个数*/
inttop;/*栈顶指针*/
}Stack;

intInitStack(Stack*S,intn)/*创建容量为n的空栈*/
{
S->elem=(int*)malloc(n*sizeof(int));
if(S->elem==NULL)return-1;
S->max=n;
S->top=0;//栈顶初值0
return0;
}

intPush(Stack*S,intitem)/*将整数item压入栈顶*/
{
if(S->top==S->max){
printf("Stackisfull! ");
return-1;
}
S->elem[S->top++]=item;//压栈,栈顶加1
return0;
}
intStackEmpty(StackS)
{
return(!S.top)?1:0;/*判断栈是否为空*/
}
intPop(Stack*S)/*栈顶元素出栈*/
{
if(!S->top){
printf("Popanemptystack! ");
return-1;
}
returnS->elem[--S->top];//弹出栈,栈顶减1
}

voidMultibaseOutput(longn,intB)
{
intm;StackS;
if(InitStack(&S,MAXSIZE)){
printf("Failure! ");
return;
}
do{
if(Push(&S,B))//------
{
printf("Failure! ");
return;
}
n=n-1;//--------
}while(n!=0);
while(!StackEmpty(S)){/*输出B进制的数*/
m=Pop(&S);
if(m<10)printf("%d",m);/*小于10,输出数字*/
elseprintf("%c",m+55);/*大于或等于10,输出相应的字符*/
}
printf(" ");
}

⑼ 栈和队列,pop,push是c语言中本身就有的还是需要自己定义

需要自己定义
栈和队列是两种数据结构,简单说就是存储数据的方式
pop和posh是栈的两种操作,相当于是两个自己定义的函数
队列没有这两个操作

热点内容
滑板鞋脚本视频 发布:2025-02-02 09:48:54 浏览:432
群晖怎么玩安卓模拟器 发布:2025-02-02 09:45:23 浏览:557
三星安卓12彩蛋怎么玩 发布:2025-02-02 09:44:39 浏览:743
电脑显示连接服务器错误 发布:2025-02-02 09:24:10 浏览:537
瑞芯微开发板编译 发布:2025-02-02 09:22:54 浏览:146
linux虚拟机用gcc编译时显示错误 发布:2025-02-02 09:14:01 浏览:232
java驼峰 发布:2025-02-02 09:13:26 浏览:651
魔兽脚本怎么用 发布:2025-02-02 09:10:28 浏览:532
linuxadobe 发布:2025-02-02 09:09:43 浏览:212
sql2000数据库连接 发布:2025-02-02 09:09:43 浏览:726