随笔分类 - 01.数据结构
摘要://java code:interface CarElementVisitor { void visit(Wheel wheel); void visit(Engine engine); void visit(Body body); void visit(Car car);} interface CarElement { void accept(CarElementVisitor visitor); // CarElements have to provide accept().} class Wheel implements CarElement { pr...
阅读全文
摘要:using System;using System.Linq;using System.Text;namespace DesignPatterns.Mediator{ //MediatorR abstract class AbstractChatroom { public abstract void Register(Participant participant); public abstract void Send(string from, string to, string message); } //ConcreteMediat...
阅读全文
摘要:http://www.cs.rpi.edu/~hollingd/psics/notes/backtracking.pdfTwo situations:– Finding a solution to a problem can't be based on astraight path to the goal.● consider traversing a maze.– We need a better approach than brute force(independently evaluating all possible solutions).● Think of the TSP
阅读全文
摘要://Singleton.cpp 默认构造函数#include <iostream>using namespace std;class Singleton{public: static Singleton* Instance();private: Singleton(){} static Singleton * _instance;};Singleton* Singleton::_instance=0;Singleton* Singleton::Instance(){ if(_instance==0){ _instance = new Singleton()...
阅读全文
摘要:#include <stdio.h>#include <stdlib.h>typedef int KeyType;struct ElemType{ int key;};int find_seq(struct ElemType arr[],int n,KeyType key){ int i=0; for(;i<n;i++){ if(arr[i].key==key)return i; printf("check %d\n",arr[i]); } return -1;}//较好的提高,for循环里只有一个判断,注意数据不能越界int find...
阅读全文