SDUT OJ 2122 資料結構實驗之連結串列七:單鏈表中重複元素的刪除
#include<iostream> #include<stdlib.h> using namespace std; typedef int ElemType; typedef struct LNode { ElemType data; struct LNode *next; }LNode,*LinkList; void show(LinkList L) { LinkList p; p=L->next; while(p) { if(p->next==NULL) cout<<p->data<<endl; else cout<<p->data<<" "; p=p->next; } } void CreateList_L(LinkList &L,int n) { LinkList p; p=new LNode; L=new LNode; L->next=NULL; LinkList q; q=new LNode; cin>>q->data; q->next=NULL; L->next=p; for(int i=2;i<=n;i++) { p=new LNode; cin>>p->data; p->next=q; L->next=p; q=p; } cout<<n<<endl; show(L); } void deletenum(LinkList &L,int n) { LinkList p,p1,p2; p=L; while(p->next!=NULL) { p1=p; p2=p->next; while(p2!=NULL) { if(p->data==p2->data) { p1->next=p2->next; p2=p2->next; n--; } else { p1=p1->next; p2=p2->next; } } p=p->next; } cout<<n<<endl; show(L); } int main() { LinkList L; int n; cin>>n; CreateList_L(L,n); deletenum(L,n); return 0; }
相關推薦
SDUT OJ 2122 資料結構實驗之連結串列七:單鏈表中重複元素的刪除
#include<iostream> #include<stdlib.h> using namespace std; typedef int ElemType; typedef struct LNode { ElemType data; stru
資料結構實驗之連結串列七:單鏈表中重複元素的刪除(SDUT 2122)
#include <bits/stdc++.h> using namespace std; typedef struct node { int data; struct no
sdut oj資料結構實驗之連結串列五:單鏈表的拆分
資料結構實驗之連結串列五:單鏈表的拆分 Time Limit: 1000MS Memory Limit: 65536KB Problem Description 輸入N個整數順序建立一個單鏈表,將該單鏈表拆分成兩個子連結串列,第一個子連結串列存放了所有的偶數,第二
資料結構實驗之連結串列一:順序建立連結串列(SDUT 2116)
Problem Description 輸入N個整數,按照輸入的順序建立單鏈表儲存,並遍歷所建立的單鏈表,輸出這些資料。 Input 第一行輸入整數的個數N; 第二行依次輸入每個整數。 Outp
資料結構實驗之連結串列三:連結串列的逆置(SDUT 2118)
題目連結 #include <bits/stdc++.h> using namespace std; struct node { int data; struct no
資料結構實驗之連結串列六:有序連結串列的建立(SDUT 2121)
#include <bits/stdc++.h> using namespace std; struct node { int data; struct node *ne
SDUTOJ-2054 資料結構實驗之連結串列九:雙向連結串列
題目連結 #include <iostream> #include <cstdlib> using namespace std; typedef int ElementType; typedef struct node { ElementType
SDUTOJ-3331 資料結構實驗之連結串列八:Farey序列
連結串列節點插入練習題 題目連結 #include <stdio.h> #include <cstdlib> using namespace std; typedef int ElementType; typedef struct node { Elemen
資料結構實驗之連結串列八:Farey序列
Problem Description Farey序列是一個這樣的序列:其第一級序列定義為(0/1,1/1),這一序列擴充套件到第二級形成序列(0/1,1/2,1/1),擴充套件到第三極形成序列(0/1,1/3,1/2,2/3,1/1),擴充套件到第四級則形成序列(0/1,
2117資料結構實驗之連結串列二:逆序建立連結串列
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }*p, *q, *tail; int main() { int
資料結構實驗之連結串列四:有序連結串列的歸併
Problem Description 分別輸入兩個有序的整數序列(分別包含M和N個數據),建立兩個有序的單鏈表,將這兩個有序單鏈表合併成為一個大的有序單鏈表,並依次輸出合併後的單鏈表資料。 Input 第一行輸入M與N的值; 第二行依次輸入M個有序的整數; 第
2117 資料結構實驗之連結串列二:逆序建立連結串列
資料結構實驗之連結串列二:逆序建立連結串列 Time Limit: 1000MS Memory Limit: 65536KB Problem Description 輸入整數個數N,再輸入N個整數,
資料結構實驗之連結串列六:有序連結串列的建立(C語言)
#include<stdio.h> #include<stdlib.h> struct ns { int m; struct ns *next; }; int main() { int n,i; struct ns
SDUTOJ 2116 資料結構實驗之連結串列一:順序建立連結串列
最近資料結構和c++相結合的實訓正在進行,鑑於一些同學還不是太懂連結串列,寫一篇部落格講解一下,若是哪裡有問題,請不吝支出,在此謝過,若是過路的大神看見了,求輕噴。。。。 說白了,連結串列就是個特殊的結構體陣列,只不過陣列是用下標找到某個節點的後繼節點,而連結串列使用一個指
資料結構實驗之連結串列一:順序建立連結串列
#include <stdio.h> #include <stdlib.h> struct node { int data; struct node *next; }; int main() { int i,n; st
資料結構實驗之連結串列一:順序建立連結串列(建構函式)
資料結構實驗之連結串列一:順序建立連結串列 Time Limit: 1000MS Memory Limit: 65536KB Problem Description 輸入N個整數,按照輸入的順
資料結構實驗之圖論七:驢友計劃【迪傑斯特拉演算法】(SDUT 3363)
分析:可以求簡單的任意兩點間最短距離的稍微變形,一個板子題。 #include <iostream> #include <bits/stdc++.h> using namespace std; int inf = 0x3fffff; int gra[100
資料結構實驗之連結串列:單鏈表中重複元素的刪除
資料結構實驗之連結串列七:單鏈表中重複元素的刪除 按照資料輸入的相反順序(逆位序)建立一個單鏈表,並將單鏈表中重複的元素刪除(值相同的元素只保留最後輸入的一個)。 Input: 第一行輸入元素個數 n (1 <= n <= 15); 第二行輸入 n 個整數,保證在 int 範
資料結構實驗之圖論七:驢友計劃__Dijkstra
Problem Description 做為一個資深驢友,小新有一張珍藏的自駕遊線路圖,圖上詳細的標註了全國各個城市之間的高速公路距離和公路收費情況,現在請你編寫一個程式,找出一條出發地到目的地之間的最短路徑,如果有多條路徑最短,則輸出過路費最少的一條路徑。 Input 連續T組資料
資料結構實驗之圖論七:驢友計劃 (Dijkstra演算法詳解)
#include<bits/stdc++.h> #define MAX INT_MAX //int型裡面最大的數 using namespace std ; int n , m ; //頂點數,邊數; int Map[550][550] ; //存放點與點之間的權值; int vis[55