随笔分类 -  数据结构

摘要:蛇形矩阵package com.zhanggaosong;/*** 蛇形矩阵* @author zhanggaosong**/public class Main {public static void main(String[] args) { int i,j,k=1; int n=6; ... 阅读全文
posted @ 2014-12-01 14:12 zhgs_cq 阅读(353) 评论(0) 推荐(0)
摘要:最短路径算法#include<stdio.h>#define N 11#define M 1000000struct node{ int num; //本来序号 int lin; //临时性标记};void main(){ int i,j,t,k,m,test; node l[N+1]; int w[N+1][N+1]={0}; int cnt=0;//统计节点数 int c[N+1]={0}; //存放节点w[1][2]=676;w[1][3]=1813;w[2][4]=842;w[2][5]=511;w[3][5]=695;w[3][6]=811;w[4][7]=110;w[4 阅读全文
posted @ 2013-06-20 12:00 zhgs_cq 阅读(1505) 评论(0) 推荐(0)
摘要:public class HalfSearch {public static int halfSearch(int a[], int x) {int mid, left, right;left = 0;right = a.length - 1; mid = (left + right) / 2;while (a[mid] != x) {if (x > a[mid]) {left = mid + 1;}else if (x < a[mid]) {right = mid - 1;} mid=(left+right)/2;}return mid;}public static void m 阅读全文
posted @ 2013-03-12 09:29 zhgs_cq 阅读(185) 评论(0) 推荐(0)
摘要:public class BubbleSort {/** * 冒泡排序法 */public static void bubbleSort(int a[]){ int temp; for(int i=0;i<a.length-1;i++){ for(int j=0;j<a.length-i-1;j++){ if(a[j]>a[j+1]){ temp=a[j+1]; a[j+1]=a[j]; a[j]=temp;} } } }public static void main(String[] args) {int a[] = { 2, 1, 4, 7, 5 };// 调用冒泡排序方 阅读全文
posted @ 2013-03-12 09:28 zhgs_cq 阅读(132) 评论(0) 推荐(0)
摘要:public class SelectSort {public static void selectSort(int a[]){int temp;/** * 采用选择法对数组a排序 */for (int i = 0; i < a.length-1; i++) {for (int j = i + 1; j < a.length; j++) {if (a[i] > a[j]) {temp = a[i];a[i] = a[j];a[j] = temp;}}}}public static void main(String[] args) {int a[] = { 2, 4, 1, 6 阅读全文
posted @ 2013-03-12 09:26 zhgs_cq 阅读(142) 评论(0) 推荐(0)