做了这么多年java,做java偏向于应用,都用别人的插件和jar包。现在面临毕业,大公司技术 笔试 离不开数据结构,整理了下别人的题目。然后自己做了下。写这里留纪念,也希望对大家有帮助! 程序都在MinGW上跑通,VC我不知道。。 1.把一个链表反向 #include
typedef   struct   List {    int num; struct List *next; }test; test *create_list() { test *head; test *first; test *temp =NULL; first=head=new test; for(int i=0;i<10;i++) { head->num=i; temp=new test; //偷懒,用C++的new了,C用内存分配函数 head->next=temp; temp->next=NULL; head=temp; } return   first; } void print(test *head) { while(head->next!=NULL) { printf("%d",head->num); head=head->next; } } test *change_list(test *head) { test *temp,*sixer; temp=head->next; head->next=NULL; while(temp->next!=NULL) { sixer=temp->next; temp->next=head; printf("%d-head-",temp->num); head=temp; temp=sixer; printf("%d-temp-",temp->num); } temp->next=head; return temp; } int   main() { test *onelist; onelist = create_list(); print(onelist); onelist = change_list(onelist); print(onelist); } 2.  一个二叉树的三种遍历方法的输出结果 前序遍历,先根接点。中序,根左边的根右边的,例子: abdgcefh,中序遍历访问顺序是dgbaechf,则其后续遍历的结点访问顺序是 a为根,dgb为左子树,echf为右子树 接下来看左子树的'前序遍历为bdg b首先被访问 可以知道b为左子树的根,与a相连 再看左子树的中序遍历dgb d和g都在b之前就被访问 所以b和g应该在b的左子树上 而dg的确定再根据前序遍历 d先被访问 则d为根 再看中序遍历也是d先被访问 可以确定g为d的右子树 左边就可以确定出来了 如果上面看懂了 右边就很简单,一样的道理 前序遍历cefh 确定c为右子树的根 再看中序遍历echf e为c的左子树,hf为c的右子树 hf的确定在看前序遍历f先被访问 f为根 中序遍历h先被访问 h为f的左子树 整棵树就出来了 3. 希表和数组的定义,区别,优缺点
百度 4.递归的折半查找算法 #include
using namespace std; void creat(int a[]) { for(int i=0;i<10;i++){ a[i]=i; } } void print(int a[]) { for(int i=0;i<10;i++){ printf("%d-",a[i]); } } int Search(int a[],int key,int left ,int right) { int mid;  while(left<=right){  mid = (left+right)/2;  if(key==a[mid]){  return mid;  }  else if(keyright = mid-1;  return Search(a,key,left,right);  }  else{  left = mid+1;  return Search(a,key,left,right);  }  }         return -1;   } int main() { int a[10]; int i; creat(a); print(a); int key; cin>>key; int left = 0;  int right = 10;  i=Search(a,key,left,right); printf("%d->%d",i,a[i]); return 1; } of()和strlen()的使用. sizeof比特字节数长度。strlen长度比如char a[2]={1,2} 吗sizeof是2,strlen是3包括了/0而且sizeof是可以测int a[]这种的int a[2]={1,2} 的sizeof是8.2个4字节int。