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);
}