void create_suffix(int *prefix,int *infix,int prefixhead,
	int prefixrear,int infixhead,int infixrear,
	int *suffix){
	if(prefixrear-prefixhead<1)
		return;
	int root_v=prefix[prefixhead];
	suffix[sp--]=root_v;

	int root_position_infix=findposition_infix(infix,infixhead,infixrear,root_v);
	int split_prefix=root_position_infix-infixhead+prefixhead+1;

	//rightsubtree:
	create_suffix(prefix,infix,split_prefix,prefixrear,root_position_infix+1,infixrear,suffix);
	//leftsubtree:
	create_suffix(prefix,infix,prefixhead+1,split_prefix,infixhead,root_position_infix,suffix);
}
Exemplo n.º 2
0
/*
**++
**  ROUTINE:	Build_Suffix_List
**
**  FUNCTIONAL DESCRIPTION:
**
**  	Builds the queue of suffixes from the right-hand side
**  of a .SUFFIXES directive.
**
**  RETURNS:	void
**
**  PROTOTYPE:
**
**  	Build_Suffix_List(char *line, int linelen)
**
**  IMPLICIT INPUTS:	None.
**
**  IMPLICIT OUTPUTS:	None.
**
**  COMPLETION CODES:	None.
**
**  SIDE EFFECTS:   	None.
**
**--
*/
void Build_Suffix_List (char *line, int linelen) {

    struct SFX *sfx;
    char *lp, *lpmax, *sp;
    int i;

    if (linelen == 0) {
    	while (queue_remove(suffixes.flink, &sfx)) mem_free_sfx(sfx);
    } else {
    	lp = line;
    	lpmax = line+linelen;
    	while (1) {
    	    while (lp < lpmax && isspace(*lp)) lp++;
    	    if (lp >= lpmax) break;
    	    sp = lp;
    	    while (lp < lpmax && !isspace(*lp)) lp++;
    	    /*
    	    ** The behaviour here is different from .SUFFIXES_AFTER and
    	    ** .SUFFIXES_BEFORE to retain compatibility with previous versions
    	    ** of MMK.  However, beware that if the suffix is already in the
    	    ** list, it will NOT be appended to the end as in previous
   	    ** versions.  However, that said the functionality will not change
    	    ** as the list is scanned from suffixes.flink, so duplicate
    	    ** entries will never be reached anyway.
    	    */
    	    create_suffix(sp, lp-sp, suffixes.blink);
    	}
    }
    set_mmssuffixes();
} /* Build_Suffix_List */
Exemplo n.º 3
0
void open_file_handlers(struct State *S)
{
        char filename[100];
        char sfx[20];
        struct Simulation *sim = &S->sim;
        sprintf(sfx, "N_%05d_mu_%02d", S->ntw.N, (int) (S->ntw.ext_current));
        create_suffix(S, sfx);
        sprintf(filename, "spikes_%s", S->sim.suffix);
        sim->spikes_file = fopen(filename, "w");
        sprintf(filename, "population_rate_%s", S->sim.suffix);
        sim->pop_rates_file = fopen(filename, "w");
}
int main(int argc, char const *argv[])
{
	int prefix[]={8,1,1,1,4,3,2,3,5,5,7,6,19,14,12,11,14,16,18};
	int infix[]={1,1,1,2,3,3,4,5,5,6,7,8,11,12,14,14,16,18,19};
	int size=sizeof(prefix)/sizeof(int);
	int *suffix=malloc(sizeof(int)*size);
	sp=size-1;
	create_suffix(prefix,infix,0,size,0,size,suffix);
	printf("suffix:\n");
	int i;
	for(i=0;i<size;i++)
		printf("%d ", suffix[i]);
	printf("\n");
	return 0;
}