
Python
文章平均质量分 75
xufei96
SDET .net C#
展开
-
python中对文件、文件夹的操作
python中对文件、文件夹的操作需要涉及到os模块和shutil模块。创建文件:1) os.mknod("test.txt") 创建空文件2) open("test.txt",w) 直接打开一个文件,如果文件不存在则创建文件转载 2011-09-27 15:35:35 · 1073 阅读 · 0 评论 -
第5章 树和二叉树(4)
3. 后序遍历(LRD)C++ Codes:templateclass Tree{public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void LevelOrder() { Tree::LevelOrder2(this->Root); //Tree::LevelOrder1(thi原创 2012-02-01 14:30:19 · 350 阅读 · 0 评论 -
第5章 树和二叉树(5)
4. 层序遍历(Level Order)C++ Codes:templateclass Tree{public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void LevelOrder() { Tree::LevelOrder(this->Root); //Tree::LevelOrd原创 2012-02-01 15:43:23 · 431 阅读 · 0 评论 -
第5章 树和二叉树(7)
例5-2 统计出二叉树中叶子结点的数目C++ Codes:templateclass TreeNode{public: T Value; TreeNode *Left; TreeNode *Right; TreeNode(TreeNode *left=0,TreeNode *right=0,T value=0) { Value=value; this->Left=l原创 2012-02-02 11:00:19 · 410 阅读 · 0 评论 -
第5章 树和二叉树(8)
例5-3 编写算法,求二叉树的深度Python Codes:class TreeNode: def __init__(self,left=0,right=0,value=0): self.Left=left self.Right=right self.Value=valueclass Tree: def __init__(原创 2012-02-02 14:22:23 · 341 阅读 · 0 评论 -
第5章 树和二叉树(10)
习题 5.10 编写算法,将二叉树中所有结点的左右子树相互交换。C++ Codes:templateclass TreeNode{public: T Value; TreeNode *Left; TreeNode *Right; TreeNode(TreeNode *left=0,TreeNode *right=0,T value=0) { Value=value;原创 2012-02-02 16:56:09 · 331 阅读 · 0 评论 -
第5章 树和二叉树(9)
习题 5.9 编写算法,求二叉树中分支结点的数目。C++ Codes:templateclass TreeNode{public: T Value; TreeNode *Left; TreeNode *Right; TreeNode(TreeNode *left=0,TreeNode *right=0,T value=0) { Value=value; this->原创 2012-02-02 16:30:52 · 319 阅读 · 0 评论 -
第7章 排序(1)
7.2简单排序方法7.2.1 直接插入排序C++ Codes:#pragma once#include "stdafx.h"templatevoid DirectInsertSort(T vec[], int length){ for(int i=0;i<length-1;++i) { for(int k=0;k<=i;++k) { if(vec原创 2012-02-06 13:16:23 · 326 阅读 · 0 评论 -
第7章 排序(4)
7.3 快速排序C++ Codes:templatevoid QuickSort(T vec[],int low, int high){ int i=low; int j=high; int k=low; while(low<high) { while(k=vec[k]) --high; int val1=vec[k]; vec[k]=vec[high];原创 2012-02-06 16:04:38 · 315 阅读 · 0 评论 -
第7章 排序(2)
7.2.2 冒泡排序C++ Codes:templatevoid BubbleSort(T vec[], int length){ for(int i=0;i<length;++i) { for(int j=0;j<length-i-1;++j) { if(vec[j]>vec[j+1]) { T val=vec[j+1]; vec[j+原创 2012-02-06 13:41:31 · 333 阅读 · 0 评论 -
第7章 排序(3)
7.2.3 简单选择排序C++ Codes:templatevoid SimpleSelectSort(T vec[],int length){ for(int i=0;i<length;++i) { int mark=i; for(int j=i;j<length;++j) { if(vec[j]<vec[mark]) mark=j; }原创 2012-02-06 14:26:56 · 283 阅读 · 0 评论 -
第7章 排序(6)
7.5 归并排序归并排序主要是二路归并排序。二路归并排序的基本思想是:将两个有序表合并为一个有序表。假设顺序表中n个记录为n个长度为1的有序表,从第1个有序表开始,把相邻的两个有序表两两合并成一个有序表,得到n/2个长度为2的有序表。如此重复,最后得到一个长度为n的有序表。Python Codes:def __Merge(arr,start1,start2,end): wh原创 2012-02-07 14:49:16 · 371 阅读 · 0 评论 -
第7章 排序(5)
7.4 堆排序C++ Codes:templatevoid HeapSort(T vec[], int length){ for(int i=0;i<length;++i) { for(int j=length-1-i;j>0;--j) { if(vec[j]>vec[(j-1)/2]) { T val=vec[j]; vec[j]=vec[(j原创 2012-02-06 16:47:01 · 291 阅读 · 0 评论 -
第5章 树和二叉树(3)
2. 中序遍历(LDR)C++ Codes:templateclass Tree{public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void InOrder() { //Tree::InOrder2(this->Root); Tree::InOrder1(this->Root);原创 2012-02-01 11:03:47 · 423 阅读 · 1 评论 -
第5章 树和二叉树(1)
树形结构是一对多的非线性结构,非常类似于自然界中的树,数据元素之间既有分支关系,又有层次关系。树形结构有树和二叉树两种,树的操作实现比较复杂,但树可以转换为二叉树进行处理。二叉树的存储结构主要有三种:顺序存储结构、二叉链表存储结构和三叉链表存储结构。采用顺序存储结构,是对非线性数据结构线性化,用线性结构来表示二叉树的结点之间的逻辑关系,所以需要增加空间。二叉树的二叉链表存储结构可以原创 2012-01-31 15:13:03 · 405 阅读 · 0 评论 -
第5章 树和二叉树(2)
5.2.5 二叉树的遍历1. 先序遍历。C++ Codes:templateclass Tree{public: TreeNode *Root; Tree(TreeNode *root) { this->Root=root; } void PreOrder() { Tree::PreOrder2(this->Root); //Tree::PreOrder1原创 2012-01-31 16:04:41 · 347 阅读 · 0 评论 -
Python数据类型
原创 2011-10-10 14:28:36 · 297 阅读 · 0 评论 -
如何安装.EGG文件
准备好蛋准备好工具安装工具:http://pypi.python.org/pypi/setuptools安装完成后在D:\Python27\Scripts文件夹中找到easy_install.exe, 在cmd中运行这个exe文件,将egg文件作为运行参数C:\Documents and Settings\10170660>C:\Python27转载 2011-10-25 15:28:31 · 6996 阅读 · 0 评论 -
Python的几个IDE或其他语言实现
.NET/Mono: IronPython,Python的C#实现,实现了与C#程序的集成。JAVA:Jython,Python的JAVA实现,实现了与JAVA dll的无缝集成。运行在JVM上。Eclipse:Pydev, Eclipse的Python插件,通过它可以在Eclipse IDE中编辑Python代码。Pyunit:Python标准库提供的一个unittest模块,是一个原创 2011-10-31 15:20:40 · 349 阅读 · 0 评论 -
学习总结:Python与C#的区别
首先,Python与JAVA一样,是一门开源的、跨多平台的语言。而C#本身不是开源的,且只能运行在Windows平台上。1. 编译性 Python是一门解释性脚本语言,源代码不需要编译可以直接运行,运行时Python字节码解释器解释源代码并执行相关命令。Python的源代码文件.py可以直接运行,如果装了Python在本地的话。而C#则需要编译为IL,运行时由CLR托管运行。2. 数据原创 2011-10-31 13:34:01 · 2062 阅读 · 0 评论 -
PyXML安装使用
PyXML是一套用Python解析和处理XML文档的工具包,包中的4DOM是完全相容于W3C DOM规范的。它包含以下内容:xmlproc: 一个符合规范的XML解析器。Expat: 一个快速的,非验证的XML解析器。sgmlop: a C helper module that can speed-up xmllib.py and sgmllib.py by a facto转载 2011-11-23 14:15:47 · 1336 阅读 · 0 评论 -
python在Linux的安装
python在Linux的安装 1)查看是否已经安装which pythonwhereis pythonpython -V 2)yum或apt来安装在Redhat系Linux上安装python, 执行: sudo yum install python 3)源码安装下载 :http://www.python.org/ftp/python/3.1.3/Pyt转载 2011-12-07 22:32:20 · 972 阅读 · 0 评论 -
Python如何实现类似于C#的索引器功能
a few python special functions:__getitem__1、__getitem__原文文档:For instance, if a class defines a method named__getitem__(), and x is an instance of this class, then x[i] is roughly equival转载 2012-01-11 16:10:46 · 267 阅读 · 0 评论 -
第2章 线性表(2)
Python实现一个顺序表的基本功能:"Algri.py"class SeqList(object): def __init__(self, length): self.MaxLength=length self.__data=range(length) self.Last=-1; "索引器get" d原创 2012-01-11 17:20:36 · 382 阅读 · 0 评论 -
第2章 线性表(5)
Python实现一个单链表:"Node.py"class Node: """description of class""" def __init__(self, val, p=0): self.data=val; self.next=p;"LinkList.py"from Node import Nodeclass LinkList:原创 2012-01-18 15:05:35 · 321 阅读 · 0 评论 -
第3章 栈和队列(2)
Python写一个利用列表[]实现栈的代码:class Stack: """Stack class in Stack.py""" def __init__(self,size): self.__maxsize=size self.__data=[] self.__top=-1 def __getitem__(self,in原创 2012-01-19 13:57:19 · 386 阅读 · 0 评论 -
第3章 栈和队列(5)
Python利用单链表实现栈与队列,栈链与队列链:"Node.py"class Node: """description of class""" def __init__(self, val, p=0): self.data=val self.next=pfrom Node import Nodeclass LinkStack:原创 2012-01-29 14:31:10 · 327 阅读 · 0 评论 -
第3章 栈和队列(4)
Python利用列表[]实现一个队列:class Queue: """description of class""" "Constructor" def __init__(self,size): self.maxsize=size self.__data=range(0,size) self.front=-1原创 2012-01-29 13:29:35 · 354 阅读 · 0 评论 -
第8章 查找(1)
8.2.2 有序表的折半查找折半查找(Binary Search)又叫二分查找,其基本思想是:在有序表中,取中间的记录作为比较对象,如果要查找记录的关键码等于中间记录的关键码,则查找成功;若要查找记录的关键码小于中间记录的关键码,则在中间记录的左半区继续查找;若要查找记录的关键码大于中间记录的关键码,则在中间记录的右半区继续查找。不断重复上述查找过程,直到查找成功,或有序表中没有所要查找的记录原创 2012-02-07 15:28:26 · 361 阅读 · 0 评论