#包含“stdlib.h“
#定義OK 1
#定義錯誤0
#定義溢出-1
//#定義EOF -1
#定義堆棧初始化大小10
#定義堆棧增量1000
#define MAXQSIZE 10
static int I = 0;
typedef char element type;
Typedef結構堆棧kNode//構造堆棧
{
ElemType * base
ElemType * top
int stacksize
} SqStack
elem type init stack(sq stack * S )//初始化堆棧
{
s-& gt;base =(elem type *)malloc(STACK _ INIT _ SIZE * sizeof(elem type));
如果(!s-& gt;基地)
{
退出(溢出);
}
s-& gt;top = S-& gt;基地;
s-& gt;stacksize = STACK _ INIT _ SIZE
返回OK;
}
elem type stack empty(sq stack * s)//確定堆棧是否為空。
{
if(S-》;top = = S-& gt;基地)
返回OK;
其他
返回錯誤;
}
element type push(sq stack * s,element type e )//堆棧操作
{
if(S-》;top-S-》;base & gt= S-》;堆棧大小)
{
s-& gt;base =(ElemType *)realloc(S-& gt;堿基,(S-》;stack size+stack increment)* sizeof(elem type));
如果(!s-& gt;基地)
{
退出(溢出);
}
s-& gt;top = S-& gt;base+S-》;stacksize
s-& gt;stack size+= stack increment;
}
* S-》;top++ = e;
返回OK;
}
element type pop(sq stack * s,element type * e )//彈出操作
{
if(S-》;top = = S-& gt;基地)
{
返回錯誤;
}
* e = *-S-& gt;頂;
//printf(“% d \ n“,e);
//返回e;
返回0;
}
void clear stack(sq stack * S )//清空堆棧。
{
s-& gt;top = S-& gt;基地;
}
ElemType line edit(sq stack * S )//文本編譯
{
char ch,e,a【30】;
int I;
ch = getchar();
while(1)
{
while(ch!=‘\ n‘‘
{
開關(通道)
{
大小寫“#”:Pop(S & amp;e);打破;//遇到“#”,彈出第壹個字符。
案例“@”:清除堆棧;打破;//遇到了“@”,因此彈出了前面的字符。
默認值:Push(S,ch);打破;//其他字符進入堆棧
}
ch = getchar();
}
I = 0;
而(!堆棧(S))
{
流行音樂e);
a【i++】= e;
}
Printf(“循環輸出結果:“);
for(-I;我& gt= 0;我-)
{
printf(“% c“,a【I】);
}
printf(“\ n請再輸入幾個字符:“);
清除堆棧;
ch = getchar();
}
返回0;
}
int main(void)
{
sq stack S;
printf(“\ n \ t \ t \ t這個程序是為了演示C語言中數據結構中的堆棧\ n \ n“);
printf(“\ t描述:首先,連續輸入幾個字符來初始化堆棧,並以換行符結束。\ n“);
printf(“\ t如果輸入字符包含“#”,將彈出其前面的字符,\ n);
printf(“\ t如果輸入字符包含“@”,它之前的所有字符都將被彈出(清除)!\ n ");
printf(“\ t程序本身非常簡單,唯壹的缺點是無限循環輸入,並且沒有結束語句!\ n ");
printf(“\ t程序的重要之處在於它的價值,這可以說是程序的不足之處!\ n ");
Printf(“祝您早日成功!\ n \ n“);
Printf(“請連續輸入幾個字符以初始化堆棧(例如:ABC):“);
init stack(& amp;s);
line edit(& amp;s);
系統(“暫停”);
返回0;
}
這就差不多夠了。。
所謂的用戶友好界面就是提示用戶輸入什麽。。。
不然用戶都不知道怎麽輸入,怎麽用?。
關鍵是提示語句。。。
他們說我暫時退出江湖了。。
我最近壹直在忙著找工作。。
但是我的朋友找到了我。。
即使妳從事JAVA,妳也必須幫助妳的朋友。。。
雖然數據結構學得不是很好。。。
但是我還沒有完全忘記。。嘿嘿。。。
祝朋友們早日成功!!!
拜拜。
對了,我忘了提壹件事。。。
只是積分而已。。。不要總是把壹切都給別人。。
這次不是妳問的,所以下次妳不會問了。。
請保存以備後用。。
稍微有點意思就可以了。。。
哥哥還是在乎那幾點。。
嘿嘿。。。。