- 最後登錄
- 2023-5-17
- 在線時間
- 211 小時
- 註冊時間
- 2008-12-24
- 閱讀權限
- 95
- 精華
- 0
- UID
- 5519821
- 帖子
- 421
- 積分
- 1448 點
- 潛水值
- 48495 米
| 成為伊莉的版主,你將獲得更高級和無限的權限。把你感興趣的版面一步步地發展和豐盛,那種滿足感等著你來嚐嚐喔。 - #include <iostream>
- #include <conio.h>
- using namespace std;
- struct Node {
- int n;
- Node *next;
- };
- void main()
- {
- Node *head = NULL, *p, *q,*z;
- int tmp, sum = 0;
- cin >> tmp;
- while (tmp != -1) {
- p = new Node();
- p->n = tmp;
- p->next = NULL;
- if (head == NULL) {
- head = p;
- //q = p;
- } else if (head->n <= tmp) { //右
- /*head->next = p;
- q = head;*/
- q = head;
- while(q->next != NULL && q->next->n <= tmp)
- q = q->next;
- p->next = q->next;
- q->next = p;
- } else if (head->n >= tmp) { //左
- /*p->next = q;
- head->next = q;
- q->next = NULL;
- head = p;*/
- p->next = head;
- head = p;
- }
- cin >> tmp;
- }
- for (p = head; p != NULL; p = p->next) {
- sum += p->n;
- cout << "\n" << p->n;
- }
- //cout << "總和為:" << sum;
- _getch();
- }
複製代碼 ... |
|