《数据结构与面向对象程序设计》实验6报告

学号 20182329 2019-2020-1 《数据结构与面向对象程序设计》实验6报告

  • 课程:《程序设计与数据结构》
  • 班级: 1823
  • 姓名: 李一卓
  • 学号:20182329
  • 实验教师:王志强
  • 实验日期:2019年10月25日
  • 必修/选修: 必修

1.实验内容

  • 学习使用链表,构建链表,记下元素。
  • 在链的基础上,学会实现节点插入、删除、输出操作;
  • 学会使用链表的排序方法,比如:冒泡法、选择排序法。
  • 学会在Android 上构建活动去实现链。

2. 实验过程及结果

  • 通过键盘输入一些整数,建立一个链表,这些数从我学号中依次取出的两位数。打印所有链表元素, 并输出元素的总数,在你的程序中,请用一个liyizhuo来纪录元素的总数。

  • 从磁盘读取一个文件, 这个文件有两个数字。
    然后从文件中读入数字1, 插入到链表第 5 位,并打印所有数字,和元素的总数。 保留这个链表,继续下面的操作。
    从文件中读入数字2, 插入到链表第 0 位,并打印所有数字,和元素的总数。 保留这个链表,并继续下面的操作。
    从链表中删除刚才的数字1. 并打印所有数字和元素的总数。

  • 使用冒泡排序法或者根据数值大小对链表进行排序。

  • 将实验1、2、3都在Android 里面实现,要修改清单,改变layout布局,java文件不用大改。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:ignore="MissingDefaultResource">

    <LinearLayout
        android:id="@+id/Second"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="9dp"
        android:orientation="vertical">
    </LinearLayout>

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView5"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textview6"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView7"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView8"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView9"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView10"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

    <TextView
        android:id="@+id/textView11"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text=""
        android:textAppearance="@style/TextAppearance.AppCompat.Medium" />

</LinearLayout>

3. 实验过程中遇到的问题和解决过程

  • 问题1:在Android 上实现实验2时,发现自己不能再layout中编写的布局中调用方法Chain6_4

  • 问题1解决方法:我在编写Second的时候缺少与之对应的布局。

  • 问题2:再实验3时,发现缺少R包,在下载R包后,发现自己编写的方法1又改变了。

  • 问题2解决方法:缺少menu活动。

其他(感悟、思考等)

在学习链的排序时,发现有很多方法可以用,不是非要冒泡法或选择排序发,哈希法取模循环排序也可以为数字排序,不过排序首先得查找,再决定用交换还是插入排序,当然最简单的线性排序交换也可以,快速排序的交换方法是最快的算法。

参考资料

posted @ 2019-10-30 23:32  李一卓  阅读(255)  评论(0编辑  收藏  举报