日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

动态栈

發布時間:2025/4/14 编程问答 16 豆豆
生活随笔 收集整理的這篇文章主要介紹了 动态栈 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
/*
?* =====================================================================================
?*
?* ? ? ? Filename: ?dynamic_stack.c
?*
?* ? ?Description: ?
?*
?* ? ? ? ?Version: ?1.0
?* ? ? ? ?Created: ?2011年10月25日 16時53分20秒
?* ? ? ? Revision: ?none
?* ? ? ? Compiler: ?gcc
?*
?* ? ? ? ? Author: ?Wang Ran (), wangran51@126.com
?* ? ? ? ?Company: ?
?*
?* =====================================================================================
?*/
#include <stdio.h>
#include <stdlib.h>
struct stack_node
{
int data;
struct stack_node *next_ptr;
};


void push(struct stack_node** node, int n);
int pop(struct stack_node** node);
int is_empty(struct stack_node* node);
void print_stack(struct stack_node* node);
void ?instructions(void);


int main()
{
struct stack_node * stack_ptr = NULL;//在第第一次push的時候NULL會被復制到top_ptr->next_ptr中
? ? //所以這句是必須的
int i, choice, value;


for(i=0; i<5; i++)
{
printf("Enter an interger:");
scanf("%d", &value);
push(&stack_ptr, value);
// print_stack(stack_ptr);
}


for(i=0;i<5;i++)
{


if(!is_empty(stack_ptr))
{
printf("the poped value is %d\n ", pop(&stack_ptr));
}
print_stack(stack_ptr);
}

printf("end of run \n ");




return EXIT_SUCCESS;
}


void instructions(void)
{
printf("Enter choice: \n 1:push\n 2:pop\n 3:end\n ");
}
void push(struct stack_node ** top_ptr, int info)
{
struct stack_node * new_ptr;
new_ptr = malloc(sizeof (struct stack_node));
if(new_ptr != NULL)
{
new_ptr->data = info;
new_ptr->next_ptr = *top_ptr;
*top_ptr = new_ptr;
}
else
{
printf("%d not inserted, No memory available. \n", info);
}
}
int pop(struct stack_node** top_ptr)
{
struct stack_node* temp_ptr;
int pop_value;
temp_ptr = *top_ptr;
pop_value = (*top_ptr)->data;
*top_ptr = (*top_ptr)->next_ptr;
free(temp_ptr);
return pop_value;
}
void print_stack(struct stack_node* current_ptr)
{
if(current_ptr == NULL)
{
printf("the stack is empty.\n");
}
else
{
while(current_ptr != NULL)
{
printf("%d-->", current_ptr->data);
current_ptr = current_ptr->next_ptr;
}
printf("NULL\n ");
}
}
int is_empty(struct stack_node * top_ptr)
{
return top_ptr == NULL;
}

總結

以上是生活随笔為你收集整理的动态栈的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。