
数据结构与算法
hym2111
这个作者很懒,什么都没留下…
展开
-
排序
1、冒泡排序: 逐个交换,将最大的值交换到最后的位置上去。 int sort(int *a, int n) { int i,j; for(i=0; i<n-1;i++) for(j=0; j<n-1-i; j++) if(a[j]>a[j+1]) { int x = a[j]; a[j] = a[j+1]; a[j+1] =原创 2012-09-26 18:57:01 · 292 阅读 · 0 评论 -
寻找数组中的第二大数
#include"iostream" using namespace std; int a[10]={1,2,12,32,22,1232,231,4223}; const int minmax=-999999; int find(int *a) { int i; int maxnumber = a[0]; int secnumber = minmax; for(i=1;i原创 2012-10-05 16:20:11 · 377 阅读 · 0 评论 -
链表倒置
#include"iostream" using namespace std; struct node { int data; struct node *next; }; typedef struct node Node; node * reverse( node * head) { node * p,*q; p=head->next;原创 2012-10-05 14:58:17 · 513 阅读 · 0 评论 -
合并有序链表
node * merge(node * head1,node * head2) { if(head1->next==NULL) return head2; if(head2->next == NULL) return head1; node * head=new node; head->next=NULL; node *q=head; node *p1原创 2012-10-05 15:31:06 · 393 阅读 · 0 评论 -
判断回文数
#include "iostream" #include"string" #include"algorithm" using namespace std; int mirr(const char *p ) { const char * q =p; int i,len =0; while(*q++!='\0') { len++; } for(i=0;原创 2012-10-06 16:32:11 · 351 阅读 · 0 评论 -
大数加法
#include "iostream" #include"string" #include"algorithm" using namespace std; string str1,str2; char str3[100]; int main() { cin>>str1; cout<<str1[0]<<endl; cin>>str2; int i,j,mi原创 2012-10-06 16:08:06 · 286 阅读 · 0 评论