SDUT OJ 資料結構實驗之鍊表五 單鏈表的拆分

2021-07-23 11:52:05 字數 878 閱讀 3654

time limit: 1000ms

memory limit: 65536kb

submit

statistic

problem description

輸入n個整數順序建立乙個單鏈表,將該單鏈表拆分成兩個子鍊錶,第乙個子鍊錶存放了所有的偶數,第二個子鍊錶存放了所有的奇數。兩個子煉表中資料的相對次序與原鍊錶一致。

input

第一行輸入整數n;;

第二行依次輸入n個整數。

output

第一行分別輸出偶數鍊錶與奇數鍊錶的元素個數; 

第二行依次輸出偶數子鍊錶的所有資料;

第三行依次輸出奇數子鍊錶的所有資料。

example input

10

1 3 22 8 15 999 9 44 6 1001

example output

4 6

22 8 44 6

1 3 15 999 9 1001

hint

不得使用陣列!

#includeusing namespace std;

struct node

;int n,m;

struct node *head2;

void split(struct node *head1)

else

p1=q;

if(q)

q=q->next;

}}int main()

split(head1);

coutnext)

for(p=head2->next;p;p=p->next)

return 0;

}

SDUT OJ 資料結構實驗之鍊表一 順序建立鍊錶

time limit 1000 ms memory limit 65536 kib submit statistic discuss problem description 輸入n個整數,按照輸入的順序建立單鏈表儲存,並遍歷所建立的單鏈表,輸出這些資料。input 第一行輸入整數的個數n 第二行依次...

SDUT OJ 資料結構實驗之鍊表二 逆序建立鍊錶

time limit 1000 ms memory limit 65536 kib submit statistic discuss problem description 輸入整數個數n,再輸入n個整數,按照這些整數輸入的相反順序建立單鏈表,並依次遍歷輸出單鏈表的資料。input 第一行輸入整數n...

SDUT OJ 資料結構實驗之鍊表九 雙向鍊錶

time limit 1000 ms memory limit 65536 kib submit statistic discuss problem description 學會了單向鍊錶,我們又多了一種解決問題的能力,單鏈表利用乙個指標就能在記憶體中找到下乙個位置,這是乙個不會輕易斷裂的鏈。但單鏈...