伊莉討論區
標題:
徵求串列高手,解決卡點問題ˊˋ
[打印本頁]
作者:
ook5002000
時間:
2009-4-7 11:18 PM
標題:
徵求串列高手,解決卡點問題ˊˋ
提示:
作者被禁止或刪除 內容自動屏蔽
作者:
include
時間:
2009-4-9 01:32 AM
#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();
}
複製代碼
歡迎光臨 伊莉討論區 (http://a401.file-static.com/)
Powered by Discuz!