Re: [理工] 資結問題(已補圖)

作者: jacksoncsie (資工肥宅)   2021-11-03 21:02:13
※ 引述《yatingiloveu (殺了他順便殺了我)》之銘言:
: 大家好,小弟我想問個問題。
: 我外系修課所以也沒有人可以討論,有點問題是想請問各位前輩能否幫我看,
: 我的「234567 」空格旁邊的藍色code有沒有寫錯。
: https://i.imgur.com/QBSMDXx.jpg
: 再來是有個地方一直看不太懂
: (1)
: Main fun
: 現在s.top=stacksize 是3
: 裡面有個 k[0] =pop()小弟我的理解是call pop這個函式後 存到 k[0]內不太明白為何
: 傳的是-1
: (2)再來是他說s.top = stacksize
: 那對於後面的程式碼有影響到嗎?他是想表示一開始s.top 指超過比整個stack上面一個
: index嗎?有點不太能理解這個操作。
: 先謝謝感謝各位前輩了。
#include <stdio.h>
#include <stdlib.h>
typedef struct listNode* listPtr;
typedef struct listNode {
int data;
listPtr link;
};
listPtr create2() {
listPtr first, second;
first = (struct listNode*)malloc(sizeof(struct listNode));
second = (struct listNode*)malloc(sizeof(struct listNode));
second->link = NULL;
second->data = 4;
first->data = 5;
first->link = second;
return first;
}
void insert(listPtr* first, listPtr x) {
listPtr temp;
temp = (struct listNode*)malloc(sizeof(struct listNode));
temp->data = 2;
if (*first) {
temp->link = x->link;
x->link = temp;
}
else {
x = temp;
x->data = temp->data;
}
}
int main() {
listPtr first;
first = create2();
insert(&first, first);
printf("The list contains: ");
for (;first;first = first->link)
printf("%d", first->data);
printf("\n");
return 0;
}
剛剛打一下 應該可以跑
作者: yatingiloveu (yo廷廷)   2021-11-03 22:22:00
謝謝jack大的回覆 還是感恩

Links booklink

Contact Us: admin [ a t ] ucptt.com