数据结构——图的两种实现办法及两种遍历
运行结果如下:
请输入建图类型(1:无权有向图、2:带权有向网、3:无权无向图、4:带权无向网):
3
建立无权无向图,请依次输入总结点数、总边数、是否包含信息:
8 8 0
请为从1至n个结点命名:
V1 V2 V3 V4 V5 V6 V7 V8
请输入8组相互依附的两结点:
V1 V2
V2 V4
V4 V8
V8 V5
V2 V5
V1 V3
V3 V6
V3 V7
打印图的邻接矩阵:
0 1 1 0 0 0 0 0
1 0 0 1 1 0 0 0
1 0 0 0 0 1 1 0
0 1 0 0 0 0 0 1
0 1 0 0 0 0 0 1
0 0 1 0 0 0 0 0
0 0 1 0 0 0 0 0
0 0 0 1 1 0 0 0
请输入深度优先搜索起始结点:
V1
深度优先搜索遍历序列:
V1 V2 V4 V8 V5 V3 V6 V7
请输入广度优先搜索起始结点:
V1
广度优先搜索遍历序列:
V1 V2 V3 V4 V5 V6 V7 V8
请输入建图类型(1:无权有向图、2:带权有向网、3:无权无向图、4:带权无向网):
3
建立无权无向图,请依次输入总结点数、总边数:
8 8
请为从1至n个结点命名:
1 2 3 4 5 6 7 8
请输入8组相互依附的两结点:
1 2
2 4
4 8
8 5
2 5
1 3
3 6
3 7
图的创建完成,该图的邻接表表示为:
0:1-->1-->2-->NULL
1:2-->0-->3-->4-->NULL
2:3-->0-->5-->6-->NULL
3:4-->1-->7-->NULL
4:5-->7-->1-->NULL
5:6-->2-->NULL
6:7-->2-->NULL
7:8-->3-->4-->NULL
请输入深度优先搜索起始结点:
1
深度优先搜索遍历序列:
1 2 4 8 5 3 6 7
请输入广度优先搜索起始结点:
1
广度优先搜索遍历序列:
1 2 3 4 5 6 7 8
请输入建图类型(1:无权有向图、2:带权有向网、3:无权无向图、4:带权无向网):
高仿微信6.0
Android学习,高仿微信6.0,public class ViewPagerAdapter extends FragmentPagerAdapter {
/**
* 聊天界面
*/
private ChatFragment chatFragment;
/**
* 发现页面
*/
private FoungFragment foundFragment;
/**
* 聊天界面
*/
private ContactFragment contactFragment;
private final String[] titles = { "聊天", "发现", "通讯录" };
public ViewPagerAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
switch (position) {
case 0:
if (chatFragment == null) {
chatFragment = new ChatFragment();
}
return chatFragment;
case 1:
if (foundFragment == null) {
foundFragment = new FoungFragment();
}
return foundFragment;
case 2:
if (contactFragment == null) {
contactFragment = new ContactFragment();
}
return contactFragment;
default:
return null;
}
}
@Override
public int getCount() {
return titles.length;
}
@Override
public CharSequence getPageTitle(int position) {
return titles[position];
}
}
二叉树的基本操作
先序遍历输入(以#结束):AB#CD##E##F#GH###
中序遍历输出:BDCEAFHG
先序遍历输出:ABCDEFGH
后序遍历输出:DECBHGFA
层序遍历输出:ABFCGDEH
树的深度:4
结点的个数:8
叶结点的个数:3
WeChatSample
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.wechat.wechat.MainActivity"
android:orientation="vertical">
<include layout="@layout/top_layout" />
<android.support.v4.view.ViewPager
android:layout_weight="1"
android:id="@+id/vp"
android:layout_width="match_parent"
android:layout_height="0dp"></android.support.v4.view.ViewPager>
<LinearLayout
android:paddingTop="10dp"
android:background="#ffffff"
android:orientation="horizontal"
android:id="@+id/rg"
android:layout_width="match_parent"
android:layout_height="60dp">
<LinearLayout
android:id="@+id/ll_home"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.wechat.wechat.view.MyImageView
android:layout_gravity="center"
android:id="@+id/iv1"
android:layout_width="30dp"
android:layout_height="30dp"/>
<TextView
android:gravity="center"
android:text="微信"
android:button="@null"
android:id="@+id/rb1"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_categroy"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.wechat.wechat.view.MyImageView
android:layout_gravity="center"
android:id="@+id/iv2"
android:layout_width="30dp"
android:layout_height="30dp"/>
<TextView
android:gravity="center"
android:text="通信录"
android:button="@null"
android:id="@+id/rb2"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_find"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.wechat.wechat.view.MyImageView
android:layout_gravity="center"
android:id="@+id/iv3"
android:layout_width="30dp"
android:layout_height="30dp"/>
<TextView
android:gravity="center"
android:text="发现"
android:button="@null"
android:id="@+id/rb3"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<LinearLayout
android:id="@+id/ll_mine"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical">
<com.example.wechat.wechat.view.MyImageView
android:layout_gravity="center"
android:id="@+id/iv4"
android:layout_width="@dimen/tab_image_weith"
android:layout_height="@dimen/tab_image_heigh"/>
<TextView
android:gravity="center"
android:text="我"
android:button="@null"
android:id="@+id/rb4"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>