Last active
June 14, 2018 09:10
-
-
Save hanjae-jea/cd822fb7c37e44a7677160bc000715c3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
typedef struct node{ | |
char value; | |
struct node* parent; | |
struct node* left, *right; | |
}node; | |
typedef node* p_node; | |
void inorder(p_node node){ | |
if( node == NULL ) return; | |
inorder(node->left); | |
printf("%c ", node->value); | |
inorder(node->right); | |
} | |
void preorder(p_node node){ | |
if( node == NULL ) return; | |
printf("%c ", node->value); | |
preorder(node->left); | |
preorder(node->right); | |
} | |
void postorder(p_node node){ | |
if( node == NULL ) return; | |
postorder(node->left); | |
postorder(node->right); | |
printf("%c ", node->value); | |
} | |
int main() | |
{ | |
p_node root = (p_node)malloc(sizeof(node)); | |
root->value = '.'; | |
root->parent = root->left = root->right = NULL; | |
root->left = (p_node)malloc(sizeof(node)); | |
root->left->value = 'L'; | |
root->left->parent = root; | |
root->left->left = root->left->right = NULL; | |
p_node newNode = (p_node)malloc(sizeof(node)); | |
newNode->value = 'U'; | |
newNode->parent = root; | |
newNode->left = newNode->right = NULL; | |
root->right = newNode; | |
newNode = (p_node)malloc(sizeof(node)); | |
newNode->value = 'A'; | |
newNode->parent = root->left; | |
newNode->left = newNode->right = NULL; | |
root->left->left = newNode; | |
newNode = (p_node)malloc(sizeof(node)); | |
newNode->value = 'B'; | |
newNode->parent = root->left; | |
newNode->left = newNode->right = NULL; | |
root->left->right = newNode; | |
newNode = (p_node)malloc(sizeof(node)); | |
newNode->value = 'X'; | |
newNode->parent = root->right; | |
newNode->left = newNode->right = NULL; | |
root->right->left = newNode; | |
newNode = (p_node)malloc(sizeof(node)); | |
newNode->value = 'Y'; | |
newNode->parent = root->right; | |
newNode->left = newNode->right = NULL; | |
root->right->right = newNode; | |
// L1, L2, U1, U2 | |
printf("전위순회 : "); | |
preorder(root); | |
printf("\n중위순회 : "); | |
inorder(root); | |
printf("\n후위순회 : "); | |
postorder(root); | |
printf("\n%c",root->value); | |
} | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main() | |
{ | |
int n; | |
char arr[] = "input.txt"; | |
FILE *in = fopen(arr, "r");// read | |
FILE *out = fopen("output.txt", "a");//write | |
//append | |
fscanf(in, "%d", &n); | |
fprintf(out, "%d", n);\ | |
fclose(in); | |
fclose(out); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment