c語言pop
⑴ 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是棧的兩種操作,相當於是兩個自己定義的函數
隊列沒有這兩個操作