Esempio n. 1
0
void BinaryTree::printPre(Node* node) {
	if (node) {
		//go right
		printPost(node->getRight());
		//go left
		printPost(node->getLeft());
		cout << node->getData() << " ";
	}
}
Esempio n. 2
0
void printPost(Node* node)
{
	if (node != NULL)
	{
		printPost(node->left);
		printPost(node->right);
		printf("%d\n", node->value);
	}
}
Esempio n. 3
0
inline void casadi_math<T>::print(unsigned char op, std::ostream &stream, const std::string& x, const std::string& y){
  if(ndeps(op)==2){
    printPre(op,stream);
    stream << x;
    printSep(op,stream);
    stream << y;
    printPost(op,stream);
  } else {
    printPre(op,stream);
    stream << x;
    printPost(op,stream);
  }
}
Esempio n. 4
0
int printPost(Node *current, FILE *output, int height){
	height = height+1;
	int height_left = 0;
	int height_right = 0;
	int new_height = 0;
	if(current->LSON!=NULL){
		height_left = printPost(current->LSON,output,height);
		height_right = printPost(current->RSON,output,height);
		if(height_left > height_right) new_height = height_left;
		else new_height = height_right;
	}
	else new_height = height;
	fprintf(output,"%c", current->data);
	return (new_height);
}
Esempio n. 5
0
int main()
{
    int nTest = 0;
    scanf("%d", &nTest);
    while (nTest-- > 0)
    {
        scanf("%d", &nNode);

        int i = 0, j = 0;
        while (i < nNode)
        {
            scanf("%d", &preorder[i]);
            i++;
        }
        while (j < nNode)
        {
            scanf("%d", &inorder[j]);
            memo[ inorder[j] ] = j;
            j++;
        }

        printPost(0, nNode);
        printf("\n");
        reset();
    }
}
Esempio n. 6
0
void printPost(int lower, int upper)
{
    if (lower > upper) return;
    if (lower >= nNode) return;
    if (upper < 0) return;
    
    int root = preorder[pos++]; // 9
    int inorderIndex = memo[ root ]; // 3 -> 2 -> 0 -> 1 -> 5 -> 4 -> 6 // 0
    
    if (inorderIndex == lower) lower++;
    if (inorderIndex == upper) upper--;
    
    printPost(lower, inorderIndex);
    printPost(inorderIndex + 1, upper);
    
    printf("%d ", root);
}
Esempio n. 7
0
void ScrapbookGUI::displayBlog(Blog* blog) {

    QString content = printPost(blog);

    QListWidgetItem* listItem = new QListWidgetItem(content);
    listItem->setData(listItemTypeRole, blogListItemType);
    listItem->setData(listItemIDRole, blog->getID());
    ui->scrapbookArea->addItem(listItem);
}
Esempio n. 8
0
void ScrapbookGUI::displayTweet(Tweet* tweet) {

    QString content = printPost(tweet);

    QListWidgetItem* listItem = new QListWidgetItem(content);
    listItem->setData(listItemTypeRole, tweetListItemType);
    listItem->setData(listItemIDRole, tweet->getID());
    ui->scrapbookArea->addItem(listItem);

}
Esempio n. 9
0
void print(Tree* tree)
{
	int choice;

	do
	{

		system("cls");
		printf("1. Print preorder\n");
		printf("2. Print postorder\n");
		printf("3. Print inorder\n");
		printf("9. Back\n");
		scanf("%d", &choice);

		switch (choice)
		{
		case 1:
			system("cls");
			printf("Printing preorder...\n\n");
			printPre(tree->root);
			printf("\n");
			system("pause");
			break;
		case 2:
			system("cls");
			printf("Printing postorder...\n\n");
			printPost(tree->root);
			printf("\n");
			system("pause");
			break;
		case 3:
			system("cls");
			printf("Printing inorder...\n\n");
			printOrder(tree->root);
			printf("\n");
			system("pause");
			break;
		case 9:
			break;
		default:
			printf("Your choice was out of range!\n");
			system("pause");
			break;
		}
	} while ((choice > 3 || choice < 1) && choice != 9);

}
Esempio n. 10
0
void ScrapbookGUI::displayMultimedia(Multimedia* multimedia) {

    QString content = multimedia->getContent();

    QString newLabel = printPost(multimedia);

    QListWidgetItem *newMedia = new QListWidgetItem(QIcon(content), newLabel, ui->scrapbookArea);


    newMedia->setData(listItemTypeRole, multimediaListItemType);
    newMedia->setData(listItemIDRole, multimedia->getID());
    ui->scrapbookArea->addItem(newMedia);

    ui->scrapbookArea->setIconSize(QSize(125,125));


}
Esempio n. 11
0
int main(int argc, char **argv, char **envp)
#endif
{
    char    *cp, *method;
    int     i, j, err;

    err = 0;
    outputArgs = outputQuery = outputEnv = outputPost = 0;
    outputBytes = outputHeaderLines = responseStatus = 0;
    outputLocation = 0;
    nonParsedHeader = 0;
    responseMsg = 0;
    hasError = 0;
    timeout = 0;
    queryBuf = 0;
    queryLen = 0;
    numQueryKeys = numPostKeys = 0;

    originalArgc = argc;
    originalArgv = argv;

#if _WIN32 && !WINCE
    _setmode(0, O_BINARY);
    _setmode(1, O_BINARY);
    _setmode(2, O_BINARY);
#endif

    if (strstr(argv[0], "nph-") != 0) {
        nonParsedHeader++;
    }
    if (getArgv(&argc, &argv, originalArgc, originalArgv) < 0) {
        error("Can't read CGI input");
    }
    for (i = 1; i < argc; i++) {
        if (argv[i][0] != '-') {
            continue;
        }
        for (cp = &argv[i][1]; *cp; cp++) {
            switch (*cp) {
            case 'a':
                outputArgs++;
                break;

            case 'b':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    outputBytes = atoi(argv[i]);
                }
                break;

            case 'e':
                outputEnv++;
                break;

            case 'h':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    outputHeaderLines = atoi(argv[i]);
                    nonParsedHeader++;
                }
                break;

            case 'l':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    outputLocation = argv[i];
                    if (responseStatus == 0) {
                        responseStatus = 302;
                    }
                }
                break;

            case 'n':
                nonParsedHeader++;
                break;

            case 'p':
                outputPost++;
                break;

            case 'q':
                outputQuery++;
                break;

            case 's':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    responseStatus = atoi(argv[i]);
                }
                break;

            case 't':
                if (++i >= argc) {
                    err = __LINE__;
                } else {
                    timeout = atoi(argv[i]);
                }
                break;

            default:
                err = __LINE__;
                break;
            }
        }
    }
    if (err) {
        fprintf(stderr, "usage: cgiProgram -aenp [-b bytes] [-h lines]\n"
            "\t[-l location] [-s status] [-t timeout]\n"
            "\tor set the HTTP_SWITCHES environment variable\n");
        fprintf(stderr, "Error at cgiProgram:%d\n", __LINE__);
        exit(255);
    }
    if ((method = getenv("REQUEST_METHOD")) != 0 && strcmp(method, "POST") == 0) {
        if (getPostData(&postBuf, &postBufLen) < 0) {
            error("Can't read CGI input");
        }
        if (strcmp(safeGetenv("CONTENT_TYPE"), "application/x-www-form-urlencoded") == 0) {
            numPostKeys = getVars(&postKeys, postBuf, postBufLen);
        }
    }

    if (hasError) {
        if (! nonParsedHeader) {
            printf("HTTP/1.0 %d %s\r\n\r\n", responseStatus, responseMsg);
            printf("<HTML><BODY><p>Error: %d -- %s</p></BODY></HTML>\r\n", responseStatus, responseMsg);
        }
        fprintf(stderr, "cgiProgram: ERROR: %s\n", responseMsg);
        exit(2);
    }

    if (nonParsedHeader) {
        if (responseStatus == 0) {
            printf("HTTP/1.0 200 OK\r\n");
        } else {
            printf("HTTP/1.0 %d %s\r\n", responseStatus, responseMsg ? responseMsg: "");
        }
        printf("Connection: close\r\n");
        printf("X-CGI-CustomHeader: Any value at all\r\n");
    }

    printf("Content-type: %s\r\n", "text/html");

    if (outputHeaderLines) {
        for (i = 0; i < outputHeaderLines; i++) {
            printf("X-CGI-%d: A loooooooooooooooooooooooong string\r\n", i);
        }
    }
    if (outputLocation) {
        printf("Location: %s\r\n", outputLocation);
    }
    if (responseStatus) {
        printf("Status: %d\r\n", responseStatus);
    }
    printf("\r\n");

    if ((outputBytes + outputArgs + outputEnv + outputQuery + outputPost + outputLocation + responseStatus) == 0) {
        outputArgs++;
        outputEnv++;
        outputQuery++;
        outputPost++;
    }

    if (outputBytes) {
        j = 0;
        for (i = 0; i < outputBytes; i++) {
            putchar('0' + j);
            j++;
            if (j > 9) {
                if (++outputBytes > 0) {
                    putchar('\r');
                }
                if (++outputBytes > 0) {
                    putchar('\n');
                }
                j = 0;
            }
        }

    } 
    printf("<HTML><TITLE>cgiProgram: Output</TITLE><BODY>\r\n");
    if (outputArgs) {
#if _WIN32
        printf("<P>CommandLine: %s</P>\r\n", GetCommandLine());
#endif
        printf("<H2>Args</H2>\r\n");
        for (i = 0; i < argc; i++) {
            printf("<P>ARG[%d]=%s</P>\r\n", i, argv[i]);
        }
    }
    printEnv(envp);
    if (outputQuery) {
        printQuery();
    }
    if (outputPost) {
        printPost(postBuf, postBufLen);
    }
    printf("</BODY></HTML>\r\n");

#if VXWORKS
    /*
        VxWorks pipes need an explicit eof string
        Must not call exit(0) in Vxworks as that will exit the task before the CGI handler can cleanup. Must use return 0.
     */
    write(1, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN);
    write(2, MPR_CMD_VXWORKS_EOF, MPR_CMD_VXWORKS_EOF_LEN);
#endif
    fflush(stderr);
    fflush(stdout);
    return 0;
}
Esempio n. 12
0
int main(){
	int i, j;  //for loops
	int choice; //option
	int height; //height of tree
	int size; //size of array
	int done = 0; //if user's done using the program, initialized as false
	int validation;

	output = fopen("2014.out","w"); //open output file

	while(done != 1){
		choice = printChoice();
		if(choice == 1){
			char data[MAX_SIZE];
			char tag[MAX_SIZE];

			//GET DATA
			printf("DATA: ");
			scanf("%[^\n]",data);
			getchar();

			//PRINT DATA ARRAY
			fprintf(output,"DATA: " );
			for(i=0;i<strlen(data);i++){
				fprintf(output,"%c", data[i]);
			}
			fprintf(output,"\n" );

			//GET TAGS
			printf("TAG: ");
			scanf("%[^\n]",tag);
			getchar();

			//PRINT TAG ARRAY
			fprintf(output,"TAG: " );
			for(i=0;i<strlen(tag);i++){
				fprintf(output,"%c", tag[i]);
			}
			fprintf(output,"\n" );

			if (strlen(data) != strlen(tag)){ //not equal input
				fprintf(output,"Input is invalid.\n\n");
			}

			else{
				getInput(data);
				getInput(tag);

				size = strlen(data);

				if(size==1 && tag[0] == '0'){ //tree with only one node
					fprintf(output,"Postorder: %c\n",data[0]);
					fprintf(output,"Levelorder: %c\n",data[0]);
					fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
					fprintf(output,"      %c\n\n",data[0]);
				}

				else if(size==1 && tag[0] == '1'){ //one node with children is invalid
					fprintf(output,"Input is invalid.\n\n");
				}

				else{
					if(tag[0] == '0'){
						fprintf(output,"Input is invalid.\n\n");
					}

					else{
						validation = valid1(tag,size);
						if(validation == -1){
							Node *root = Tree(data,tag,size);
							fprintf(output,"Postorder: ");
							height = printPost(root,output,0);
							fprintf(output,"\nLevel Order: ");
							for(i=0;i<height;i++){
									printLevel(root, i, output);
							}
							fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
							printTable(root,output);
							fprintf(output,"\n\n");
						}
						else{
							fprintf(output,"Input is invalid.\n\n");
						}
					}
				}
			}
		}

		else if(choice == 2){
			char filename[MAX_SIZE];
			char data_array[MAX_SIZE];
			char tag_array[MAX_SIZE];
			char data = ' ';
			int index = 0;

			printf("Filename: ");
			scanf("%s",filename);

			input = fopen(filename,"r");

			while(!feof(input)){
				index = 0;
				while(index < MAX_SIZE){
					data_array[index] = ' ';
					tag_array[index] = -1;
					index++;
				}
				index = 0;
				while(data!=':' && !feof(input)){
					data = fgetc(input);
				}
				fgetc(input);
				while(data!='\n' && !feof(input)){
					data = fgetc(input);
					if(data!=' '){
						data_array[index] = data;
						index++;
					}
				}
				int index = 0;
				while(data!=':' && !feof(input)){
					data = fgetc(input);
				}
				fgetc(input);
				data = fgetc(input);
				while(data!='\n' && !feof(input)){
					if(data!=' '){
						tag_array[index] = atoi(&data);
						index++;
					}
					data = fgetc(input);
				}

				fprintf(output,"DATA: " );
				int i;
				for(i=0;i<index;i++){
					if(i==index-1){
						fprintf(output,"%c", data_array[i]);
					}
					else{
					fprintf(output,"%c", data_array[i]);
					}
				}
				fprintf(output,"\n"); 

				fprintf(output,"TAG: " );
				for(i=0;i<index;i++){
					fprintf(output,"%d", tag_array[i]);
				}
				fprintf(output,"\n");

				int size = strlen(data_array);

				if(index==1 && tag_array[0] == 0){
					fprintf(output,"Postorder: %c\n",data_array[0]);
					fprintf(output,"Levelorder: %c\n",data_array[0]);
					fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
					fprintf(output,"      %c\n\n",data_array[0]);
				}
				else if(index==1 && tag_array[0] != 1){
					fprintf(output,"Input is invalid.\n\n");
				}
				else{
					//print(tag_array,size1);
					if(tag_array[0] == 0){
						fprintf(output,"Input is invalid.\n\n");
					}
					else{
						int validation = valid2(tag_array,index);
						if(validation == -1){
							Node *head_node = Tree2(data_array,tag_array,index);
							fprintf(output,"Postorder: ");
							height = printPost(head_node, output,0);
							fprintf(output,"\nLevelorder: ");
							int i = 0;
							for(i=0;i<height;i++){
								printLevel(head_node, i, output);
							}
							fprintf(output,"\nTable: \nLSON NODE RSON\n--------------\n");
							printTable(head_node,output);
							fprintf(output,"\n\n");
							}
						else{
							fprintf(output,"Input is invalid.\n\n");
						}
					}
				}
			}
			fclose(input);
		}

		else if(choice==3){
			printf("Exits.\n");
			done = 1;
		}

		else{
			printf("Wrong input.\n");
		}
	}
	fclose(output);
}