摘要: View Code #include <stdio.h>#include <stdlib.h>typedef struct node{ int data; struct node* next;}Link;int a[10]={12,34,503,2,12,5,74,7,112,6};Link* CreateLink(){ int i; Link *head,*tail; head=(Link* )malloc(sizeof(Link)); head->data=0; tail=head; Link* p; for (i=0; i<10; +... 阅读全文
posted @ 2012-05-20 00:31 徐露 阅读(232) 评论(0) 推荐(0) 编辑
摘要: Prime算法View Code #include <stdio.h>#include <stdlib.h>#define MAX 100/********ÁÚ½Ó¾ØÕó½á¹¹***************/typedef struct graph{ char vers[MAX]; int numVertex,numEdge; int arc[MAX][MAX];}Graph;void CreateGraph(Graph *G){ int i,j; 阅读全文
posted @ 2012-05-11 09:44 徐露 阅读(196) 评论(0) 推荐(0) 编辑
摘要: 题目:类CMyString的声明如下:class CMyString{public: CMyString(char* pData = NULL); CMyString(const CMyString& str); ~CMyString(void); CMyString&operator= (const CMyString& str);private: char* m_pData;}; 请实现其赋值运算符的重载函数,要求异常安全,即当对一个对象进行赋值时发生异常,对象的状态不能改变。要求异常安全,应该禁止使用new和delete操作View C... 阅读全文
posted @ 2012-05-10 23:45 徐露 阅读(224) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #include <string.h> 3 4 int Strlen(const char *str) 5 { 6 if (str==NULL) 7 { 8 return 0; 9 }10 if (*str != '\0')11 {12 return 1+Strlen(++str);13 }14 else 15 return 0;16 }17 18 int Strlen1(const char* str)19 {... 阅读全文
posted @ 2012-05-10 23:15 徐露 阅读(142) 评论(0) 推荐(0) 编辑
摘要: 要求不能使用乘除法、for、while、if、else、switch、case 等关键字以及条件判断语句View Code 1 #include <iostream> 2 using namespace std; 3 4 /*第一种方案*/ 5 int sum1(int n) 6 { 7 int temp=0; 8 n && (temp=sum1(n-1)); 9 return temp+n;10 }11 /* 第二种方案 */12 class A13 {14 public:15 A()16 {17 N++;18 s... 阅读全文
posted @ 2012-05-10 19:14 徐露 阅读(145) 评论(0) 推荐(0) 编辑
摘要: View Code 1 #include <stdio.h> 2 #include <stdlib.h> 3 #define MAXLEN 10 4 #define K 3 5 6 7 void HeapAdjust(int array[], int i, int len) 8 { 9 int temp=array[i];10 int j;11 for (j=2*i; j<len; j*=2)12 {13 if (j<len && array[j] < array[j+1])14 {15 ... 阅读全文
posted @ 2012-05-10 18:25 徐露 阅读(168) 评论(0) 推荐(0) 编辑
摘要: 算法设计:1、当访问到某一节点时,把该结点的值添加到当前和变量,且把该结点压vector中。2、若结点为叶子结点,且当前和变量等于期望的和,则打印vector中的结点值,即为所需的路径。3、若结点不是叶子结点,继续访问它的左孩子结点,访问它的右孩子结点。4、删除该结点。包括从当前和变量中减去结点值,从vector中弹出结点值。#include <iostream>#include <vector>#include <stdlib.h>using namespace std;typedef struct node{ int data; struct node* 阅读全文
posted @ 2012-05-10 16:15 徐露 阅读(479) 评论(0) 推荐(0) 编辑
摘要: #include <iostream> using namespace std; int maxSum(int* a, int n) { int sum=0; int b=0; for(int i=0; i<n; i++) { if(b<0) b=a[i]; else b+=a[i]; if(sum<b) sum=b; } return sum; } int maxSu... 阅读全文
posted @ 2012-05-10 15:07 徐露 阅读(197) 评论(0) 推荐(0) 编辑
摘要: (1)递归的方式递归二叉数#include <stdio.h>#include <stdlib.h>typedef struct node{ char data; struct node *lchild; struct node *rchild;}Node;void creatBT(Node* T){ char ch; scanf("%c", &ch); if ('.'==ch) { return; } else { T=(Node *)malloc(sizeof(Node)); if (T==NULL) { exit(0); 阅读全文
posted @ 2012-05-09 19:23 徐露 阅读(245) 评论(0) 推荐(0) 编辑
摘要: 题目:写一个函数f(N),返回1到N之间出现的"1"的个数。(1)循环遍历1-N,分别求每个数字的中包含1的个数。#include <iostream>using namespace std;int Count(long num){ int temp=0; while (num) { temp+=num % 10 == 1 ? 1 : 0; num/=10; } return temp;}int main(){ long num=100000000; long i; int total=0; for (i=1; i<=num; ++i) { total+= 阅读全文
posted @ 2012-05-09 16:23 徐露 阅读(221) 评论(0) 推荐(0) 编辑