java語言交集并集差集的程序設(shè)計報告.doc_第1頁
java語言交集并集差集的程序設(shè)計報告.doc_第2頁
java語言交集并集差集的程序設(shè)計報告.doc_第3頁
java語言交集并集差集的程序設(shè)計報告.doc_第4頁
java語言交集并集差集的程序設(shè)計報告.doc_第5頁
已閱讀5頁,還剩2頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

課 程 設(shè) 計 課程名稱 Java語言課程設(shè)計 題目名稱 集合的并、交和差運算 學(xué)生學(xué)院 應(yīng)用數(shù)學(xué)學(xué)院 專業(yè)班級_ 11信息安全(2)_學(xué) 號 3111008245 學(xué)生姓名 吳辰修 指導(dǎo)教師 劉科峰 2013 年 10 月 28 日一、課程設(shè)計的內(nèi)容用Java語言實現(xiàn)單鏈表的基本操作,并實現(xiàn)集合的并、交和差運算。多人合作的要使用圖形界面進行數(shù)據(jù)輸入、輸出。二、課程設(shè)計的要求與數(shù)據(jù)所寫報告要表達清楚,讓老師明白你做了哪些工作,掌握了哪些知識。你所做的課程設(shè)計有何特點和優(yōu)點。三、程序設(shè)計思想、源代碼 通過單鏈表實現(xiàn)集合的交、并、差運算。主要有三部分:節(jié)點的構(gòu)造、單鏈表的建立、集合的三個運算。 /* * To change this template, choose Tools | Templates * and open the template in the editor. */package set;class LNode char data; LNode next; LNode() data= ; next=null; LNode(char data1,LNode next1) /節(jié)點的構(gòu)造方法(特殊的重載) data = data1; next = next1; public void setData(char data1) data = data1; public char getData() return data; public void setNext(LNode next1) next = next1; public LNode getNext() return next; public class Set LNode head; / 頭結(jié)點 int length; / 長度 Set() /鏈表的構(gòu)造方法 head = new LNode(); /調(diào)用子類的構(gòu)造方法 length = 0; public void Initset(char data1) /用char數(shù)組創(chuàng)建集合鏈; for (int i = 0; i data1.length; +i) Inset(data1i); public void Inset(char item) /用char類型數(shù)據(jù)插入節(jié)點的方法 LNode LNode = new LNode(item, null); /創(chuàng)建一個節(jié)點LNode LNode temp = head; /增加一個節(jié)點 LNode.setNext(head.getNext(); head.setNext(LNode); length+; public void delete(int n) /在指定位置刪除節(jié)點方法; if(nlength) System.out.print(位置不存在!); LNode temp = head; for(int i=0; in-1;i+) temp = temp.getNext(); temp.setNext(temp.getNext().getNext(); length-; public void print() /遍歷所有節(jié)點,輸出每個節(jié)點數(shù)據(jù); LNode temp = head; System.out.print(); while (temp.getNext() != null) System.out.print(temp.getNext().getData() + ,); temp = temp.getNext(); System.out.print(); System.out.println(鏈表長度為:+length); public Set jiaoji(Set set1, Set set2) Set set3 ; set3=new Set(); LNode temp1 = set1.head.getNext(); /temp1引用鏈表set1的第一個結(jié)點 LNode temp2 = set2.head.getNext(); /temp2引用鏈表set2的第一個結(jié)點 while (temp1 != null & temp2 != null) while (temp2 != null) if (temp1.getData() = temp2.getData() set3.Inset(temp1.getData(); temp2 = temp2.getNext(); /引用不斷往后移 temp1 = temp1.getNext(); /當前引用不斷往下移 temp2 = set2.head; / 回到頭結(jié)點 System.out.printf(兩集合的交集為: ); return set3; public Set bingji(Set set1, Set set2) Set set4; set4=new Set(); LNode temp1 = set1.head.getNext(); /指向頭結(jié)點的下一個結(jié)點 LNode temp2 = set2.head.getNext(); while (temp1 != null) /相當于求差集; while (temp2 != null) if (temp1.getData() = temp2.getData() break; temp2 = temp2.getNext(); if (temp2 = null) set4.Inset(temp1.getData(); temp2 = set2.head.getNext(); temp1 = temp1.getNext(); while (temp2 != null) /插入set2數(shù)據(jù); set4.Inset(temp2.getData(); temp2 = temp2.getNext(); System.out.printf(兩集合的并集為:); return set4; public Set chaji(Set set1, Set set2) Set set5; set5=new Set(); LNode temp1 = set1.head.getNext(); /set1當前的位置 LNode temp2 = set2.head.getNext(); while (temp1 != null & temp2 != null) while (temp2 != null) if (temp1.getData() = (temp2.getData() /兩數(shù)據(jù)相同,則跳出該循環(huán); break; temp2 = temp2.getNext(); if (temp2 = null) /插入temp1的數(shù)據(jù)到set5;即得到集合1中與集合2不同的數(shù)據(jù); set5.Inset(temp1.getData(); temp1 = temp1.getNext(); temp2 = set2.head; System.out.printf(集合1減去集合2的差集為:); return set5; public static void main(String args) Set set1 = new Set(); Set set2 = new Set(); Set set3 = new Set(); Set set4 = new Set(); Set set5 = new Set(); char ch1=1,2,3,4,; char ch2=2,3,4,5 ; set1.Initset(ch1); set2.Initset(ch2); System.out.printf(集合1為: ); set1.print(); System.out.printf(集合2為: ); set2.print(); set3=set1.jiaoji(set1, set2); set3.print(); set4=set1.bingji(set1, set2); set4.print(); set5=set1.chaji(set1, set2); set5.print(); 運行結(jié)果: 4、 問題探討與總結(jié) 這次為期一周的Java語言課程設(shè)計對我印象極為深刻,開始時,我還感到比較的迷茫,僅僅可以用一些基本的知識來寫一些基本的語句,而對于集合運算整個程序的設(shè)計卻是非常迷茫,經(jīng)過一周的學(xué)習(xí),加上同學(xué)的請教等現(xiàn)在對于自己的程序達到了完全的理解,在以后同樣的問題上,我相信自己就可以很輕松的解決了。在這期間我們也遇到了好多的困難,但是通過老師的教導(dǎo)和對一些文獻的參考等,使得我對知識有了更加深入的了解,這對我們以后的工作有很大的幫助,在這里向老師表示由衷的感謝。一周的Java語言課程設(shè)計結(jié)束了。原計劃的設(shè)計思想也基本實現(xiàn),回首整個過程,我深刻的體會到了學(xué)無止境的道理,不僅加深了我對數(shù)據(jù)結(jié)構(gòu)知識的了解和掌握,而且對程序的設(shè)計也有了更加深入的體會。與此同時,我的設(shè)計報告仍然有一些不足之處,一些集合元素判斷問題等沒有設(shè)計。因此不是很完美,但是學(xué)習(xí)的真正目的在

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論