亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

關于經典停車場問題指針輸出亂碼問題?

發布時間:2020-07-04 10:21:54 來源:網絡 閱讀:408 作者:wqwq800123 欄目:編程語言

邀請好友加入騰訊云自媒體分享計劃
給好友發送邀請鏈接,好友成功加入計劃后你和好友都分別獲得 30 / 100 / 180 元云服務器代金
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
struct stackstruct /棧的結構體/
{
int id;
int time;
struct stackstruct pre;
struct stackstruct
next;
};

struct queuestruct //隊列結構體
{
int id;
struct queuestruct *next;
};

struct stackstruct stackhead1, stackend1;
struct stackstruct stackhead2, stackend2;
struct queuestruct queuehead, queueend;
int stack1count, stack2count; /棧中元素總數/
int queuecount; /隊列中元素總數/

void push(int flag, struct stackstruct p)
{
struct stackstruct
stack;
if (flag == 0) /棧1進棧操作/
{
if (stack1count == 0)//棧1空
{
stackhead1 = (struct stackstruct )malloc(sizeof(struct stackstruct));
stackhead1->id = p->id;
stackhead1->time = p->time;
stackhead1->next = NULL;
stackhead1->pre = NULL;
stackend1 = stackhead1;
}
else
{
stack = (struct stackstruct
)malloc(sizeof(struct stackstruct));
stack->id = p->id;
stack->time = p->time;
stackend1->next = stack;
stack->pre = stackend1;
stack->next = NULL;
stackend1 = stack;
}
stack1count++;
}
else if (flag == 1) /棧2進棧操作,棧1出棧/
{
if (stack2count == 0)//棧2空
{
stackhead2 = (struct stackstruct )malloc(sizeof(struct stackstruct));
stackhead2->id = p->id;
stackhead2->time = p->time;
stackhead2->next = NULL;
stackhead2->pre = NULL;
stackend2 = stackhead2;
}
else
{
stack = (struct stackstruct
)malloc(sizeof(struct stackstruct));
stack->id = p->id;
stack->time = p->time;
stackend2->next = stack;
stack->pre = stackend2;
stack->next = NULL;
stackend2 = stack;
}
stack2count++;
}
}

struct stackstruct pop(int id, int time)
{
struct stackstruct
stack;
stack = (struct stackstruct *)malloc(sizeof(struct stackstruct));

if (stackend1->id != id)
{
    stack->id = stackend1->id;
    stack->time = stackend1->time;
    stack->pre = stackend1->pre;
    stackend1=NULL;
    stackend1 = stack->pre;
    stackend1->next = NULL;
    stack1count--;
}
else
{
    stack->id = stackend1->id;
    stack->time = stackend1->time;
    stack->pre = stackend1->pre;
    printf("%d號汽車出停車場\n",id);
    printf("停車場停留時間: %d\n",time - stack->time);
    printf("應該繳納的費用(單價: 5): %d\n", 5 * (time - stack->time));
    stackend1=NULL;
    if (--stack1count == 0)
        stackend1 = stackhead1 = NULL;
    else
    {
        stackend1 = stack->pre;
        stackend1->next = NULL;
    }
    stack = NULL;
}
return stack;

}

struct stackstruct pop1()//棧2元素出棧
{
struct stackstruct
stack;
stack = (struct stackstruct *)malloc(sizeof(struct stackstruct));

stack->id = stackend2->id;
stack->time = stackend2->time;
stack->pre = stackend2->pre;
free(stackend2);
stackend2 = stack->pre;
stack2count--;

return stack;

}

void Enqueue(struct stackstruct p)//入隊
{
struct queuestruct
queue;
if (queuecount == 0)
{
queuehead = (struct queuestruct )malloc(sizeof(struct queuestruct));
queuehead->id = p->id;
queuehead->next = NULL;
queueend = queuehead;
}
else
{
queue = (struct queuestruct
)malloc(sizeof(struct queuestruct));
queue->id = p->id;
queue->next = NULL;
queueend->next = queue;
queueend = queue;
}
queuecount++;
}

struct stackstruct Dequeue(int time)//出隊
{
struct stackstruct
stack;
stack = (struct stackstruct *)malloc(sizeof(struct stackstruct));

stack->id = queuehead->id;
stack->time = time;
if (--queuecount == 0)
{
    queuehead = NULL;
    queueend = NULL;
}
else
    queuehead = queuehead->next;
return stack;

}
int main()
{
int n;
char s = {0};
struct stackstruct p;
printf("輸入狹長通道可停放汽車數量: ");
scanf_s("%d", &n);
getchar();
stack1count = stack2count = queuecount = 0;
p = (struct stackstruct
)malloc(sizeof(struct stackstruct));
printf("輸入停車信息:(動作,車牌號,時間)\n");
while (scanf_s("%c,%d%d", &s,1, &p->id, &p->time) != EOF)
{
if (s =='E')
{
printf("End");
break;
}
if (s =='A') /汽車到達/
{
if (stack1count < n) /棧未滿,進棧操作/
{
push(0, p);
printf("%d號汽車進入停車場\n",p->id);
printf("進入停車場時間: %d\n",stackend1->time);
printf("停車位置: %d\n",stack1count);
}
else /棧滿,進隊列操作/
{
Enqueue(p);
printf("%d號汽車進入便道\n",p->id);
printf("進入便道時間: %d\n",p->time);
printf("便道位置: %d\n",queuecount);
}
}
if (s =='D') /汽車離去/
{
struct stackstruct *temp;
while ((temp = pop(p->id, p->time)) != NULL)
{
push(1, temp);
}
while (stack2count != 0)
{
push(0, pop1());
}
if (queuecount != 0)
{
push(0, Dequeue(p->time));
printf("%d號汽車進入停車場\n",stackend1->id);
printf("進入時間: %d\n",stackend1->time);
printf("停車位置: %d\n",stack1count);
}
}
}
return 0;
}
我的博客即將同步至騰訊云+社區,邀請大家一同入駐:https://cloud.tencent.com/developer/support-plan?invite_code=hiyc3ueo3ntk

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

双流县| 白朗县| 库伦旗| 始兴县| 宣化县| 铜川市| 吉木萨尔县| 莲花县| 广汉市| 龙岩市| 神农架林区| 瑞安市| 改则县| 太湖县| 石柱| 怀来县| 亚东县| 任丘市| 靖江市| 平罗县| 邳州市| 乌鲁木齐县| 南丰县| 巴塘县| 湟中县| 闻喜县| 常山县| 宣城市| 巩义市| 新建县| 庆云县| 获嘉县| 盐亭县| 漳浦县| 农安县| 额尔古纳市| 阿拉善左旗| 包头市| 松江区| 渭南市| 莱阳市|