91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 1.05 KB
    文件類型: .rar
    金幣: 1
    下載: 0 次
    發布日期: 2024-12-27
  • 語言: 其他
  • 標簽:

資源簡介

1、掌握順序棧的類型定義方法。
2、掌握在順序棧上實現的六種基本算法。
2、掌握順序棧的簡單應用。
利用順序棧將一個非負的十進制整數N轉換為對應的B進制數。
[基本要求]非負的十進制整數N和B都從鍵盤輸入;轉換結果從屏幕輸出。

資源截圖

代碼片段和文件信息

//?數據結構實驗三.cpp?:?Defines?the?entry?point?for?the?console?application.
//

#include?“stdafx.h“
#include
#define?maxlen?100
using?namespace?std;
typedef?struct
{
int?s[maxlen];
int?top;
}Stack;
//初始化棧
void?InitStack(Stack?&st)
{
st.top=-1;
}
//進棧
int?push(Stack?&stint?x)
{
if(st.top==maxlen-1)
return?0;
else
{
st.top++;
st.s[st.top]=x;
return?1;
}
}
//出棧
int?pop(Stack?&stint?&x)
{
if(st.top==-1)
return?0;
else?
{
????????x=st.s[st.top];
st.top--;
return?x;
}
}
//取棧頂元素
int?gettop(Stack?&stint?&x)
{
if(st.top==-1)
{
return?0;
}
else?
{
x=st.s[st.top];
return??x;
}
}
//判斷棧是否為空
int?StackEmpty(Stack?st)
{
if(st.top?==?-1)
{
return?1;
}
else
{
return?0;
}
}
//求棧的長度
int?StackLength(Stack?st)
{
return?st.top+1;
}

//數制轉換
void?conversion(Stack?&st)
{
int?nx=0n1;
char?ch;
while(1)
{
????cout<<“請輸入一個十進制數:\n“;
????cin>>n;
????cout<<“請輸入你要轉換的進制:\n“;
????cin>>n1;
if(n1==0)
break;
???????while(n)
{
??????push(stn%n1);
??????n=n/n1;
}
while(!StackEmpty(st))
{
??pop(stx);
??cout< }
}

}
int?main(int?argc?char*?argv[])
{
int?x=0x1=0n;
int?s[maxlen];
Stack?stst1;
????InitStack(st);
?InitStack(st1);
while(1)
{
??????cout<<“請輸入入棧的元素個數(n<100):\n“;
??????cin>>n;
??????if(n<=maxlen)
???????break;
}
??
????for(int?i=0;i {
cout<<“請輸入第“< cin>>s[i];
push(sts[i]);//入棧
}
???cout<<“當前棧的長度為:“< ???cout<<“當前棧頂為:“< ???cout<<“當前棧彈出1個元素為:“<???????if(!StackEmpty(st))
?????????cout<<“當前棧頂為:“< ???cout< ???conversion(st1);//數制轉換
???????system(“pause“);
return?0;
}

?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----

?????文件???????1988??2010-10-24?21:59??棧的實現及應用\數據結構實驗三.cpp

?????目錄??????????0??2010-11-04?20:53??棧的實現及應用

-----------?---------??----------?-----??----

?????????????????1988????????????????????2


評論

共有 條評論

相關資源