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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 运维知识 > windows >内容正文

windows

栈子系统c语言,数据结构(栈子系统:c实现)

發(fā)布時(shí)間:2025/3/20 windows 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 栈子系统c语言,数据结构(栈子系统:c实现) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

#include

#include

#define N sizeof(stacknode)//結(jié)點(diǎn)所占字節(jié)數(shù) N

//定義結(jié)構(gòu)體

typedef int datatype;

typedef struct stacknode

{

datatype data;

struct stacknode *next;

}stacknode;

//定義棧頂

typedef struct

{

stacknode *top;

int count;//計(jì)數(shù)用

}linkstack;

//進(jìn)棧,元素一一進(jìn)棧

void InsertStack(linkstack *s)

{

int x=0;

stacknode *p;

s->top=NULL;

s->count=0;

//printf("\n\t建立一個(gè)棧子系統(tǒng)");

p=(stacknode*)malloc(N);

printf("\n\t\t請(qǐng)逐個(gè)輸入數(shù)字,結(jié)束標(biāo)記位,做結(jié)束符的數(shù)字: 0 \n");

while(1)

{

/*printf("\t\t請(qǐng)輸入:");

fflush(stdin);

if(!scanf("%d",&x))

{

printf("輸入的元素種類錯(cuò)誤!!!\n");

continue;

}

else if(x=='#') break;

else

{

p->data=x;

p->next=s->top;

s->top=p;

s->count++;

}

*/

printf("\t\t請(qǐng)輸入:");

p=(stacknode*)malloc(N);

fflush(stdin);

if(!scanf("%d",&x))

{

printf("\t\t\t輸入的“元素“種類錯(cuò)誤!!!\n");

continue;

}

else if(x==0)

break;

else

{

p->data=x;

p->next=s->top;

s->top=p;

s->count++;

}

}

printf("\n");

}

//顯示棧中元素

void ShowStack(linkstack *s)

{

stacknode *p;

int i=0;

p=s->top;

i=s->count;

//p->data=s->top->data;

//if(p->next==NULL)

if(i==0)

printf("\t\t棧是一個(gè)空棧!!!!\n");

else

{

printf("\t棧中各個(gè)元素為:\t");

while(i!=0)

{

printf("%8d",p->data);

p=p->next;

//s->top=s->top->next;

i--;

}

}

printf("\n");

}

//求棧中元素的個(gè)數(shù)

void LengthStack(linkstack *s)

{

printf("\t棧中元素的個(gè)數(shù)為:\t");

printf("%d",s->count);

}

//出棧,棧中各個(gè)元素的出棧

void PutStack(linkstack *s)

{

//int x;

stacknode *p;

//linkstack *i;

if(s->count==0)

{

printf("\t\t棧是一個(gè)空棧!!!!");

//return 0;

}

else

{

/*

p=s->top;

x=p->data;

s->top=p->next;

free(p);

//s->count-=1;

*/

p=s->top;

s->top=s->top->next;

printf("\n\t\t\t\t出棧元素為:%d\n",p->data);

free(p);

s->count--;

}

}

//數(shù)制轉(zhuǎn)換,十進(jìn)制轉(zhuǎn)換為二進(jìn)制

void ShiftStack(linkstack *s)

{

int z=0;

int m=0;

stacknode *p;

printf("請(qǐng)輸入所要轉(zhuǎn)換的 ”數(shù)字“ Z:\t");

scanf("%d",&z);

s->top=NULL;

while(z)

{

m=z%2;

z=z/2;

p=(stacknode*)malloc(N);

p->next=s->top;

s->top=p;

s->top->data=m;

}

printf("\n\t轉(zhuǎn)化后的二進(jìn)制為\t");

while(s->top)

{

p=s->top;

printf("%d",p->data);

s->top=s->top->next;

free(p);

}

printf("\n");

}

int main()

{

int a;

linkstack s;

s.count=0;

//linkstack *s;

while(1)

{

printf(" \n\t\t\t\t\t\t棧子系統(tǒng)\n");

printf(" \t\t***************************************************\n");

printf(" \t\t* 1------進(jìn) 棧 *\n");

printf(" \t\t* 2------出 棧 *\n");

printf(" \t\t* 3------顯示棧中元素 *\n");

printf(" \t\t* 4------求棧中元素個(gè)數(shù) *\n");

printf(" \t\t* 5------數(shù)制轉(zhuǎn)換 *\n");

printf(" \t\t* 0------返 回 *\n");

printf(" \t\t***************************************************\n");

printf(" 請(qǐng)輸入(0-5)選項(xiàng):\n");

printf("\n請(qǐng)輸入所要達(dá)到第幾號(hào)功能:\t");

fflush(stdin);

scanf("%d",&a);

if(a == 1)

InsertStack(&s);

else if(a == 2)

PutStack(&s);

else if(a == 3)

ShowStack(&s);

else if(a == 4)

LengthStack(&s);

else if(a == 5)

ShiftStack(&s);

else if(a == 0)

return 0;

else{

printf("!!!!!輸入有誤,請(qǐng)重新輸入!!!!!\n");

}

}

}

總結(jié)

以上是生活随笔為你收集整理的栈子系统c语言,数据结构(栈子系统:c实现)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。