1. 写一个入栈函数push(),要求输入一个字符串1234,并将结果1234保存 2. 写一个出栈函数pop(),输出结果

发布网友 发布时间:2022-04-23 14:19

我来回答

1个回答

热心网友 时间:2023-10-17 23:37

只要理解堆栈的结构就不难了,后入先出,先入后出。

unsigned char* CurrPoint;//指向最后入的一个元素
unsigned char* Stack_Base;//堆栈基址
unsigned char Array[] = "1234";
unsigend char ArrayLength = 4;//字符串长度
(unsigned char*) push(unsigned * array)
{
while((*array) != '\0')
{
*CurrPoint = *array;
array --;
CurrPoint ++;
}
return(CurrPonit--);
}
(unsigned char *) pop(unsigned char arrlen)
{
unsigned char i;
for(i = 0; i < arrlen && CurrPoint > Stack_Base; i++ )
{
printf("%c", (*CurrPoint));
CurrPoint --;
}
printf("\r\n");
return(CurrPoint);
}

热心网友 时间:2023-10-17 23:37

只要理解堆栈的结构就不难了,后入先出,先入后出。

unsigned char* CurrPoint;//指向最后入的一个元素
unsigned char* Stack_Base;//堆栈基址
unsigned char Array[] = "1234";
unsigend char ArrayLength = 4;//字符串长度
(unsigned char*) push(unsigned * array)
{
while((*array) != '\0')
{
*CurrPoint = *array;
array --;
CurrPoint ++;
}
return(CurrPonit--);
}
(unsigned char *) pop(unsigned char arrlen)
{
unsigned char i;
for(i = 0; i < arrlen && CurrPoint > Stack_Base; i++ )
{
printf("%c", (*CurrPoint));
CurrPoint --;
}
printf("\r\n");
return(CurrPoint);
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com