恒邪

2014年3月19日 #

数据结构上机实验:单链表操作

摘要: #include #include using namespace std;typedef struct Node{ char c; struct Node *next;}*LinkList,LNode;//初始化单链表hLinkList Init(LinkList &h){ h=(LNode*)malloc(sizeof(LNode)); if(h==NULL) { coutnext=NULL; return h;}//尾差法插入元素void InsertNum(LinkList &h,int n){ LinkList r,s; ... 阅读全文

posted @ 2014-03-19 21:02 恒邪 阅读(165) 评论(0) 推荐(0) 编辑

筛选求n以内素数并返回个数

摘要: #include using namespace std;const int maxn=10000;int prime[maxn];bool is_prime[maxn+1];int sieve(int n)//返回n以内素数的个数{ int p=0; for(int i=0;i<=n;i++) is_prime[i]=true; is_prime[0]=is_prime[1]=false; for(int i=2;i<=n;i++) { if(is_prime[i]) { prime[p++]=i;... 阅读全文

posted @ 2014-03-19 20:13 恒邪 阅读(200) 评论(0) 推荐(0) 编辑

优先队列

摘要: #include #include #include using namespace std;struct node{ friend bool operatorq1; for(i=0;i,greater >q2; for(i=0;iq3; node b[len]; b[0].priority=6;b[0].value=1; b[1].priority=9;b[1].value=5; b[2].priority=2;b[2].value=3; b[3].priority=8;b[3].value=2; b[4].priority=1;b[4]... 阅读全文

posted @ 2014-03-19 20:12 恒邪 阅读(116) 评论(0) 推荐(0) 编辑

最长递增子序列

摘要: #include using namespace std;//int num[8]={0,0,3,1,2,4,1,5};//原始序列int num[8]={0,1,3,4,2,5,6,7};int d[8];//保存最长递增子序列的元素,第二种方法,复杂度低int dp[8];//第一种方法,复杂度高,dp[i]存储从num[1]到num[i]之间最长递增子序列的长度,num[i]一定在里边int BinSearch(int key,int i,int low,int high)//二分搜索,找到road[i]在d[]数组中的位置{ int l=low,r=high; while(... 阅读全文

posted @ 2014-03-19 20:10 恒邪 阅读(148) 评论(0) 推荐(0) 编辑

导航