mydjm

 

2012年5月10日

链表插入操作~

摘要: 1 #include <iostream> 2 using namespace std; 3 4 5 typedef struct node 6 { 7 int data; 8 struct node* next; 9 }Node;//节点结构体10 11 12 Node* create(int n)//初始化头指针为空~13 {14 Node* head=(Node*)(malloc(sizeof(Node)));15 head->next=NULL;16 head->data=n;17 return head;18 }19 20 voi... 阅读全文

posted @ 2012-05-10 10:33 mydjm 阅读(420) 评论(0) 推荐(0) 编辑

字符串转换为整数(大数会用到滴)

摘要: 1 #include <iostream> 2 using namespace std; 3 4 void main() 5 { 6 int num=0,i=0; 7 char c[20],temp[20]; 8 cout<<"请输入字符串:"<<endl; 9 cin>>c;10 strcpy(temp,c);11 while (temp[i]!='\0')12 {13 num=num*10+temp[i]-'0';14 i++;15 }16 cout<<"整数为:&qu 阅读全文

posted @ 2012-05-10 10:26 mydjm 阅读(379) 评论(0) 推荐(0) 编辑

整数转换成字符串(大数会用到滴)

摘要: 1 #include <iostream> 2 #include <complex> 3 using namespace std; 4 5 void main() 6 { 7 int temp,num,i=0; 8 char c[20]; 9 cout<<"请输入整数"<<endl;10 cin>>num;11 temp=num;12 13 while(temp!=0)14 {15 c[i]=temp%10+'0';16 i++;17 temp/=10;18 }19 ... 阅读全文

posted @ 2012-05-10 10:15 mydjm 阅读(341) 评论(0) 推荐(0) 编辑

2012年5月6日

多态~

摘要: 1 #include <iostream> 2 using namespace std; 3 4 class Person 5 { 6 public: 7 int age; 8 int name; 9 virtual void pee()10 {11 cout<<"man stand and woman sit"<<endl;12 }13 };14 15 class man : public Person16 {17 void pee()18 {19 cout<<"man stand~"<<en 阅读全文

posted @ 2012-05-06 14:48 mydjm 阅读(147) 评论(0) 推荐(0) 编辑

构造函数的参数给值~

摘要: 1 #include <iostream> 2 using namespace std; 3 4 class A 5 { 6 protected: 7 int m_data; 8 public: 9 A(int data=1)//给了个值~10 {11 m_data=data;12 }13 int GetData()14 {15 return m_data;16 }17 };18 19 void main()20 {21 A a(2);22 A b;//无参,别加括号,那会变成函数~23... 阅读全文

posted @ 2012-05-06 14:46 mydjm 阅读(170) 评论(0) 推荐(0) 编辑

2012年3月22日

快速排序

摘要: 1 void qs(int s,int e) 2 { 3 int x=a[s],l=s,r=e;//以第一个数为参照做比较 4 if(l>=r)return; 5 while(l<r) 6 { 7 while(l<r&&a[r]>=x) 8 r--; //不小于分界值的留在右边,遇到小于的停止 9 a[l]=a[r]; 10 while(l<r&&a[l]<=x) 11 l++; //小于分界值的留在左边,遇到... 阅读全文

posted @ 2012-03-22 19:52 mydjm 阅读(132) 评论(0) 推荐(0) 编辑

冒泡排序

摘要: 1 #include<stdio.h> 2 3 void BubbleSort(int *a,int n) 4 { 5 int temp,i,j; 6 for(i=1;i<n-1;i++)//从1开始,每次j都从最后一个数开始往前比较,直到j遇到i。因为i前面的比较完成的了。 7 for(j=n-1;j>=i;j--) 8 { 9 if(a[j-1]>a[j])10 {11 temp = a[j];12 a[j] = a[j-1];... 阅读全文

posted @ 2012-03-22 15:57 mydjm 阅读(160) 评论(0) 推荐(0) 编辑

堆排序

摘要: 1 #include<stdio.h> 2 3 void MaxHeapify(int *a,int i,int len) 4 {//a为数组,i为需要保证最大堆性质的位置,len为数组中要排序的个数 5 int l=2*i;//i的左子女,数组是从1开始的 6 int r=2*i+1; 7 int largest,temp; 8 if((l<=len)&&(a[l]>a[i])) 9 largest = l;10 else largest = i;11 12 if((r<=len)&&(a[r]>a[largest]))13 阅读全文

posted @ 2012-03-22 08:44 mydjm 阅读(202) 评论(0) 推荐(0) 编辑

2012年3月20日

递归插入排序

摘要: 1 #include<stdio.h> 2 3 4 void Insert(int *a,int n)//把数组a的第n个数插入前n-1个数中,注意前n-1个数已经是排好序的了 5 { 6 int i=n-1; 7 int key=a[n]; 8 while((i>=0)&&(key<a[i])) 9 {10 a[i+1]=a[i];11 i--;12 }13 a[i+1]=key;14 return;15 }16 17 void InsertionSort(int *a,int n)//递归插入,跟... 阅读全文

posted @ 2012-03-20 23:27 mydjm 阅读(2978) 评论(0) 推荐(0) 编辑

插入排序

摘要: 1 #include<stdio.h> 2 3 int a[10],i,j,n,key; 4 void InsertionSort(int *a,int n)//*a才对 5 { 6 for(j=1;j<n;j++) 7 { 8 key=a[j]; 9 i=j-1;10 while((i>=0)&&(key<a[i]))11 {12 a[i+1]=a[i];13 i--;14 }15 a[i+1]=key;16 }17 }1... 阅读全文

posted @ 2012-03-20 18:56 mydjm 阅读(135) 评论(0) 推荐(0) 编辑

导航