摘要:这题是一栈题,开始我用数组模拟做,改了一上午没改得出,最后放弃了,后来跟白神一起做时,白神发现错误了,也是我犯的错误,像 4 1234 2134 这种也可以啊。。。 我明白了,中间也可以出栈。先把两个字符串存起来,然后先进栈,若遇到出栈的信息且要出的那辆车刚好在栈顶就可以出。否则就进栈#include<stdio.h>#include<string.h>int n,c,num1[11],num2[11],rec[11],L[11];int main( ){ int i,j,cnt,k; while( scanf( "%d",&n ) == 1
阅读全文
摘要:这个题是考数据结构的二叉排序树,对每个输入的字符串都建立一棵二叉树,然后进行先序遍历,进行后序遍历( 因为由两个遍历可以确定一棵树 ),所以每次只要先建立一棵树,然后把他们的先序遍历和后序遍历比较,若都相等就YES,否则NO#include<stdio.h>#include<string.h>#include<stdlib.h>typedef struct Node{ int data; struct Node *lc,*rc;}node,*Link;int n,f,c,cnt;char f1[11],la1[11],f2[11],la2[11];void
阅读全文
摘要:用二叉排序树写一个#include<stdio.h>typedef struct Node{ int data; struct Node *lc,*rc;}node,*Link;int n,f;inline int fab( int a ){ return a > 0 ? a : -a;}void insert( Link *L,int x ){ if( *L ) { if( fab( x ) > fab( ( *L ) -> data ) ) insert( &( *L ) -> lc,x ); else insert( &( *L ) -
阅读全文
摘要:这两天要弄数据结构考试,就在写二叉排序树二叉排序树总共三个操作:插入,查找,删除,遍历;先提醒对于插入,删除等要改变这棵树的操作都要用二维指针,否则不能改变,而遍历( 打印 ),查找( 这里的查找因为要为删除服务,所以用了二维指针,其实纯粹的查找是不需要的 )不需改变他的值,所以不用二维指针插入:小的往左边放,大的往右边放,相等的直接不要,然后递归处理就可以了。查找:如果查找的值等于当前节点,则返回当前节点,若查找的值比当前节点小则在当前节点的左子树中去找,若比当前节点大,则在当前右子树中去找,若差找不成功,返回NULL;删除:这个是最令我头痛的,开始按数据结构上的来,一直改不对,就一直在找事
阅读全文
摘要:第一次有点理解,写了个二叉树#include<stdio.h>#include<stdlib.h>typedef struct Node{ char ch; struct Node *lc,*rc;}node,*Link;void Create( Link *L ){ char ch; while( scanf( "%c",&ch ),ch == ' ' || ch == '\n' ); if( ch == '#' ) *L = NULL; else { ( *L ) = new node; (
阅读全文
摘要:#include<stdio.h>#include<string.h>struct E{ char name[1000]; char less[1000]; int d; int num; }e[60024];int c = 0,max = 0,count = 0;void swap( int x,int y ){ struct E t; t = e[ x ]; e[ x ] = e[ y ]; e[ y ] = t; }int cmp( int x,int y ){ if( e[ x ].d == e[ y ].d ) if( e[x].num < e[y].n
阅读全文