日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

数据结构上机测试2-2:单链表操作B

發(fā)布時間:2024/8/23 编程问答 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数据结构上机测试2-2:单链表操作B 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

題目描述

按照數(shù)據(jù)輸入的相反順序(逆位序)建立一個單鏈表,并將單鏈表中重復(fù)的元素刪除(值相同的元素只保留最后輸入的一個)。

輸入

第一行輸入元素個數(shù)n;
第二行輸入n個整數(shù)。

輸出

第一行輸出初始鏈表元素個數(shù);
第二行輸出按照逆位序所建立的初始鏈表;
第三行輸出刪除重復(fù)元素后的單鏈表元素個數(shù);
第四行輸出刪除重復(fù)元素后的單鏈表。

示例輸入

10 21 30 14 55 32 63 11 30 55 30

示例輸出

10 30 55 30 11 63 32 55 14 30 21 7

30 55 11 63 32 14 21

#include <iostream> #include<bits/stdc++.h> using namespace std; struct node {int data;node *next; }; struct node *create(int n) {int i;node *head,*p;head=new node;head->next=NULL;for(i=0;i<n;i++){p=new node;scanf("%d",&p->data);p->next=head->next;head->next=p;}return (head); }; void print(struct node *p) {struct node *h=p->next;while(h!=NULL){if(h->next==NULL)printf("%d",h->data);elseprintf("%d ",h->data);h=h->next;} } void num(node *head) {int i=0;node *p=head->next;while(p){i++;p=p->next;}printf("%d\n",i); } void del(node *p)//刪除重復(fù)元素; {node *h;h=p->next;node *q,*t;while(h){q=h;while(q->next){if(h->data==q->next->data){t=q->next;q->next=t->next;free(t);}elseq=q->next;}h=h->next;} } int main() {int n;scanf("%d",&n);node *p=create(n);num(p);print(p);printf("\n");del(p);num(p);print(p);return 0; }

總結(jié)

以上是生活随笔為你收集整理的数据结构上机测试2-2:单链表操作B的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。