課程名稱:《程序設計與數據結構》 學生班級:1723班 學生姓名:唐才銘 學生學號:20172319 實驗教師:王志強老師 課程助教:張師瑜學姐、張之睿學長 實驗時間:2018年09月30日——2018年10月08日 必修/選修:必修
返回目錄html
返回目錄前端
返回目錄java
public void add(int number){ Linked_list_node Node = new Linked_list_node(number); if (this.head==null){ this.head = Node; } else { this.head.addLinked_list_node(Node); } }
System.out.println("實驗的第一部分:"); System.out.print("Enter some integers and create a linked list : "); Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); String[] strings = input.split(" "); Stack<String> Break_up = new Stack<String>(); for (int i = strings.length; i > 0 ; i--){ Break_up.push(strings[i-1]); } System.out.print("The contents of the stack are : "); System.out.println(Break_up); Linked_list linked_list = new Linked_list(); linked_list.add(0); while (!Break_up.empty()) { int tempelement = Integer.parseInt(Break_up.pop()); linked_list.add(tempelement); } int ntangcaiming = 0; ntangcaiming = linked_list.getCount(); System.out.print("The contents of the queue are : "); System.out.println(linked_list); System.out.print("The number of linked elements is : "); System.out.println(ntangcaiming);
運行結果截圖:
node
爲了更好地實現需求,咱們在鏈表前端放入了一個取值爲0的節點linked_list.add(0);
,以便於在任何地方都能實現插入刪除,而打印時將其隱藏。git
public void insert(int index,Linked_list_node node){ if(index < 1||index > getCount() + 1){ System.out.println("Wrong position, cannot insert"); return; } int length = 1; Linked_list_node temp = head; while(head.next != null) { if(index == length++){ node.next = temp.next; temp.next = node; return; } temp = temp.next; } } public void delete(int index){ if(index < 1 || index > getCount()){ System.out.println("Wrong position, cannot be deleted"); return; } int length=1; Linked_list_node temp = head; while(temp.next != null){ if(index == length++){ temp.next = temp.next.next; return; } temp = temp.next; } }
System.out.println("實驗的第二部分:"); try { File file = new File("D:\\huawei\\Javawindows文件","EXP1-First semester of sophomore.txt"); InputStreamReader reader = new InputStreamReader(new FileInputStream(file)); BufferedReader bufferedReader = new BufferedReader(reader); int[] file_word_temp = new int[2]; String[] file_word = bufferedReader.readLine().split(" "); file_word_temp[0] = Integer.parseInt(file_word[0]); file_word_temp[1] = Integer.parseInt(file_word[1]); Linked_list_node Node_insert1 = new Linked_list_node(file_word_temp[0]); Linked_list_node Node_insert2 = new Linked_list_node(file_word_temp[1]); linked_list.insert(5,Node_insert1); System.out.print("The list after inserting 1 at the fifth position is : "); System.out.println(linked_list); System.out.print("The number of linked elements is : "); ntangcaiming = linked_list.getCount(); System.out.println(ntangcaiming); linked_list.insert(1,Node_insert2); System.out.print("The list after inserting 2 at the first position is : "); System.out.println(linked_list); ntangcaiming = linked_list.getCount(); System.out.print("The number of linked elements is : "); System.out.println(ntangcaiming); System.out.print("The list after deleting the inserted number 1 is : "); linked_list.delete(6); System.out.println(linked_list); ntangcaiming = linked_list.getCount(); System.out.print("The number of linked elements is : "); System.out.println(ntangcaiming);
運行結果截圖:
windows
線性結構之鏈表(2)數組
冒泡代碼實現以下(有刪減):服務器
public void Bubble_sort(Linked_list_node Head,Linked_list linked_list){ Linked_list_node temp = null, tail = null; temp = head; int count=1; while(temp.next != tail){ while(temp.next != tail){ if(temp.number > temp.next.number){ int temp_number = temp.number; temp.number = temp.next.number; temp.next.number = temp_number; System.out.print("The list sorted by the "+ count + " truly bubbling sort is : "); System.out.println(linked_list); System.out.print("The number of linked elements is : " + linked_list.getCount() + "\n" ); count++; } temp = temp.next; } tail = temp; temp = head; } }
System.out.println("實驗的第三部分:"); System.out.println("Print only the rounds that have implemented the element exchange:"); linked_list.Bubble_sort(linked_list.head,linked_list); } catch (IOException E){ System.out.println("錯誤,指定路徑不存在"); }
運行結果截圖(僅僅展現部分截圖):
網絡
本次提交點相關代碼以下:數據結構
System.out.println("實驗的第一部分:"); System.out.print("Enter some integers and create a linked list:"); Scanner scanner = new Scanner(System.in); String input = scanner.nextLine(); int ntangcaiming = 0 ; String[] temp_MyArray = input.split(" "); Array MyArray = new Array(temp_MyArray); System.out.print("The elements in the array are: "); System.out.println(MyArray); System.out.print("The number of elements in the array is: "); ntangcaiming = MyArray.size(); System.out.println(ntangcaiming); System.out.println("實驗的第二部分:"); try { File file = new File("D:\\huawei\\Javawindows文件","EXP1-First semester of sophomore.txt"); InputStreamReader reader = new InputStreamReader(new FileInputStream(file)); BufferedReader bufferedReader = new BufferedReader(reader); int[] file_word_temp = new int[2]; String[] file_word = bufferedReader.readLine().split(" "); file_word_temp[0] = Integer.parseInt(file_word[0]); file_word_temp[1] = Integer.parseInt(file_word[1]); System.out.print("The array after 1 is inserted in position 5 is : "); Array MyArray1 = new Array(MyArray.Array_Insert(4, String.valueOf(file_word_temp[0]))) ; System.out.println(MyArray1); System.out.print("The number of elements in the array is: "); ntangcaiming = MyArray1.size(); System.out.println(ntangcaiming); System.out.print("The list after inserting 2 at the first position is : "); Array MyArray2 = new Array(MyArray1.Array_Insert(0, String.valueOf(file_word_temp[1]))); System.out.println(MyArray2); System.out.print("The number of elements in the array is: "); ntangcaiming = MyArray2.size(); System.out.println(ntangcaiming); System.out.print("The array after deleting the inserted number 1 is : "); Array MyArray3 = new Array(MyArray2.Array_Delete(5)); System.out.println(MyArray3); System.out.print("The number of elements in the array is: "); ntangcaiming = MyArray3.size(); System.out.println(ntangcaiming);
public String Array_Selection_sort() { int[] temp_MyArray = new int[MyArray.length]; for (int i = 0 ; i < MyArray.length; i ++){ temp_MyArray[i] = Integer.parseInt(MyArray[i]); } String result = ""; for (int i = 0; i < temp_MyArray.length - 1 ; i++){ for (int j = i + 1;j < temp_MyArray.length; j++ ){ if (temp_MyArray[i]<temp_MyArray[j]){ int temp = temp_MyArray[i]; temp_MyArray[i] = temp_MyArray[j]; temp_MyArray[j] = temp; String every = ""; for (int data : temp_MyArray){ every += data + " "; } result += "The list sorted by the SelectSorting is : " + every + "\n" + "The number of elements in the array is: :" + MyArray.length + "\n"; } } } return result; }
System.out.println("實驗的第三部分:"); System.out.print(MyArray3.Array_Selection_sort());
解決:起初,在網絡上找了個教程(張昊然同窗也發過,但沒注意看......),按着教程走,結果:
而後針對他們瘋狂地找解決方法例如:git pull origin master --allow-unrelated-histories
但依舊無效,這鬼東西整了我一個星期,最後,張昊然同窗說多是建立的項目的緣由,而後刪了項目重建,
語言依舊是Android,其餘兩個無所謂,但別勾選使用remade初始化項目,最終獲得了:
然而它並不能簡單地經過右鍵刪除:
經過了解知道:這是一種對於APP的保護機制,要想刪除,只能經過:
然而,這僅僅是刪除在Android studio上的,要想完全刪除,還需去相應文件存儲的硬盤裏刪掉相應文件。
Intellj IDEA 簡易教程
Android開發簡易教程
Android studio項目上傳至oschina(碼雲)教程