This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//以BFS作为基础,增加两个数组,u是指定起始点 | |
bool visited5[10] = {false}; | |
void BFS_MIN_Distance(Graph g,int u) | |
{ | |
int d[g.numVertices];//记录各个顶点到起始点的最短路径长度 | |
int path[g.numVertices];//记录各个顶点在最短路径中的前驱 | |
queue <int> q;//用于BFS的队列 | |
for(int i = 0;i < g.numVertices;i++)//初始化两个数组 | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void swapNode(TNode *tree) | |
{ | |
if(tree != NULL)//递归出口 | |
{ | |
swapNode(tree->lchild); | |
swapNode(tree->rchild);//两次递归结束,得到的是有左右孩子的节点 | |
TNode *temp = tree->lchild; | |
tree->lchild = tree->rchild; | |
tree->rchild = temp; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void bubble_sort(int *a,int n) | |
{ | |
for(int i = 0;i < n;i++) | |
{ | |
for(int j = 0;j <n-i;j++) | |
{ | |
if(a[j] < a[j-1]) | |
{ | |
swap(a[j],a[j-1]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void Move(int a[],int length) | |
{ | |
int i,j;//分别从前后找 | |
i=0; | |
j=length-1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//双向冒泡 | |
void bsort(int a[],int n) | |
{ | |
//范围的左右两端 | |
int low=0,high=n-1; | |
//一趟是否交换过 初始化 | |
bool flag=true; | |
//!!!!循环条件 左端<右端并且一趟有交换 最重要 | |
while(low<high&&flag) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Definition for a binary tree node. | |
* public class TreeNode { | |
* int val; | |
* TreeNode left; | |
* TreeNode right; | |
* TreeNode() {} | |
* TreeNode(int val) { this.val = val; } | |
* TreeNode(int val, TreeNode left, TreeNode right) { | |
* this.val = val; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void deleteSame(SeqList &l) | |
{ | |
if(l.length <= 0) | |
{ | |
cout<<"wrong"<<endl; | |
exit(1); | |
} | |
int temp = 0; | |
for(int i = 1;i < l.length;i++) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//时间复杂度比下面的方法小 | |
<template class T> | |
bool deleteX(SeqList &l,T s,T t) | |
{ | |
int k = 0; | |
if(s < 1 || t > l.length || l.length == 0) | |
{ | |
cout<<"wrong"<<endl; | |
exit(0); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template class T> | |
bool deleteX(SeqList &l,T x) | |
{ | |
int k = 0; | |
if(l.length<1 || l.length >l.maxSize) | |
return false; | |
for(int i = 0;i < l.length;i++) | |
{ | |
if(l.data[i] == x) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template class T> | |
bool revert(SeqList &l) | |
{ | |
if(l.length<1 || l.length >l.maxSize) | |
return false; | |
T temp = 0; | |
for(int i = 0;i < l.length/2;i++) | |
{ | |
temp = l.data[i]; | |
l.data[i] = l.data[l.length-1-i]; |