The following code displays my created binary tree from left to right on the console window. How do I print it from the top to the bottom, as you would on paper?
// Binary Trees Implementation
#include<stdio.h>
#include<stdlib.h>
typedef struct BTNode
{
int key;
struct BTNode *left, *right;
};
void displayBT(BTNode *p, int level);
BTNode *buildBT();
void RSD(BTNode *p);
void SRD(BTNode *p);
void SDR(BTNode *p);
int main()
{
int op;
BTNode *root;
do
{
printf("\n 1. Build Binary Tree");
printf("\n 2. Display Binary Tree");
printf("\n 3. Display Traversals");
printf("\n 0. Exit");
printf("\n........................\n");
scanf("\n %d", &op);
switch(op)
{
case 1:
root=buildBT();
break;
case 2:
displayBT(root,0);
break;
case 3:
printf("\n Pre-Order:");
RSD(root);
printf("\n In-Order:");
SRD(root);
printf("\n Post-Order:");
SDR(root);
printf("\n.....................\n");
break;
}
} while(op);
}
BTNode *buildBT()
{
int value;
BTNode *p;
printf("\n k=");
scanf("%d",&value);
if(value!=0)
{
p=(BTNode *)malloc(sizeof(BTNode));
p->key = value;
p->left = buildBT();
p->right = buildBT();
} else p=NULL;
return p;
}
void displayBT(BTNode *p, int level)
{
if(p!=NULL)
{
displayBT(p->right, level+1);
for(int j=0; j<=level;j++)
printf(" ");
printf("%d \n", p->key);
displayBT(p->left, level+1);
}
}
void RSD(BTNode *p)
{
if(p!=NULL)
{
printf("%d ", p->key);
RSD(p->left);
RSD(p->right);
}
}
void SRD(BTNode *p)
{
if(p!=NULL)
{
SRD(p->left);
printf("%d ", p->key);
SRD(p->right);
}
}
void SDR(BTNode *p)
{
if(p!=NULL)
{
SDR(p->left);
SDR(p->right);
printf("%d ", p->key);
}
}
Ok so I uploaded the full code because I was having trouble with the suggestions and maybe I should have done this from the beginning.
gave it another go, actually tried it now. works for me
void print_box(FILE* out, int i)
{
static char buff[16] = {0};
sprintf(buff,"%d",i);
int n = strlen(buff);
static char buf2[16] = {0};
strcpy(buf2,"[ ]");
int nn = 2 - (n-1)/2 ;
for(i=0;i<n;++i)
buf2[nn+i] = buff[i];
fprintf(out,"%s",buf2);
}
void print_empty_box(FILE* out) { fprintf(out,"%s","[ - ]"); }
typedef struct NodeRowTag
{
struct NodeRowTag* nxt;
BTNode* node;
} NodeRow;
NodeRow* make_head()
{
NodeRow* nr;
nr = (NodeRow*) malloc(sizeof(NodeRow));
nr->node = 0;
nr->nxt = 0;
return nr;
}
void push_back( NodeRow* nr, BTNode* n )
{
while( nr->nxt )
{
nr = nr->nxt;
}
nr->nxt = (NodeRow*) malloc(sizeof(NodeRow));
nr->nxt->node = n;
nr->nxt->nxt = 0;
}
void del_all( NodeRow* nr )
{
if( nr->nxt )
del_all(nr->nxt);
free( nr );
}
NodeRow* print_and_next( FILE* out, NodeRow* nr, int rownum, int maxnum )
{
// init spacing
int spacing = 0;
int stride = 3;
for(int i=rownum; i<maxnum; ++i)
{
spacing += stride;
stride *= 2;
}
for(int i=0;i<spacing;++i)
fprintf(out, " " );
// inbetween spacing
spacing = 1;
stride = 6;
for(int i=rownum; i<maxnum; ++i)
{
spacing += stride;
stride *= 2;
}
//
NodeRow* nxt = make_head();
NodeRow* n = nr->nxt;
while(n)
{
BTNode* p = n->node;
if(p) {
print_box(out,p->key);
push_back(nxt,p->left);
push_back(nxt,p->right);
} else {
print_empty_box(out);
push_back(nxt,0);
push_back(nxt,0);
}
for(int i=0;i<spacing;++i)
fprintf(out, " " );
n=n->nxt;
}
fprintf(out, "\n" );
del_all(nr);
return nxt;
}
int max(int a,int b) { return (a>b)?a:b; }
int max_depth( BTNode* p )
{
if(!p) return 0;
return 1 + max( max_depth(p->left), max_depth(p->right) );
}
void PrittyPrint( FILE* out )
{
int n = max_depth(root);
NodeRow* nr = make_head();
push_back(nr,root);
for(int i=1; i<=n; ++i)
{
nr = print_and_next( out, nr, i, n );
}
del_all(nr);
}
By printing the value of the current node BEFORE recursing right/left!
Related
I'm new to programming, while I know there are better codes out there for this question I sort of don't understand why this isn't working, the value returned by pop2() here is a part of a string which is why for %d it doesn't print the correct value but for %c it does
int n = pop2();
printf("n is now %c\n", n);
thus even numbers are of string type for s = "3[a2[c]]" I want my loop to run the number of times that is returned by pop (2 and then 3 in this case), since the value returned by pop2() is of char type even after using atoi it doesn't work
I tried doing
int n = atoi(pop2());
//or even
char* n = pop2();
int num = atoi(n);
but it still wouldn't work, here's the entire code of the function, I've typed out printf statements to help me recognize where I was going wrong, I'd be so grateful if you don't mind helping me out. Thanks :)
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>
#include <ctype.h>
struct node
{
int data;
struct node *link;
} *top = NULL;
struct node2
{
int data;
struct node2 *link;
} *top2 = NULL;
int isEmpty()
{
if (top == NULL)
{
return 1;
}
return 0;
}
int isEmpty2()
{
if (top2 == NULL)
{
return 1;
}
return 0;
}
int pop()
{
if (isEmpty())
{
return 0;
}
int val;
val = top->data;
top = top->link;
return val;
}
int pop2()
{
if (isEmpty2())
{
return 0;
}
int val;
val = top2->data;
top2 = top2->link;
return val;
}
void push(int data)
{
struct node *new = (struct node *)malloc(sizeof(struct node));
if (new == NULL)
{
exit(1);
}
new->data = data;
new->link = NULL;
new->link = top;
top = new;
}
void push2(int data)
{
struct node2 *new = (struct node2 *)malloc(sizeof(struct node2));
if (new == NULL)
{
exit(1);
}
new->data = data;
new->link = NULL;
new->link = top2;
top2 = new;
}
int peek()
{
if (isEmpty())
{
return 0;
}
return top->data;
}
int peek2()
{
if (isEmpty2())
{
return 0;
}
return top2->data;
}
char *decodeString(char *s, char *arr)
{
for (int i = 0; i < strlen(s); i++)
{
if (s[i] == '[')
{
printf("pushing s[i] that is %c on stack 1\n", s[i]);
push(s[i]);
}
if (isalpha(s[i]))
{
printf("pushing %c on stack 2\n", s[i]);
push2(s[i]);
}
if (isdigit(s[i]))
{
printf("pushing %c on stack 2\n", s[i]);
push2(s[i]);
}
if (s[i] == ']')
{
if (peek() == '[')
{
printf("s[i] is %c and peek element is %c \n", s[i],
peek());
printf("%c is now popped out next element in stack one is %c\n", pop(), peek());
if (isalpha(peek2()))
{
printf("element in stack 2 now is %c\n", peek2());
char ch = pop2();
printf("ch now is %c\n", ch);
strcat(arr, &ch);
printf("arr after strncating is:");
printf("%s ", arr);
printf("\n");
}
if (isdigit(peek2()))
{
printf("element in stack 2 now is %c\n", peek2());
int n = pop2();
printf("n is now %c\n", n);
printf("current arr is %s\n", arr);
while (n < 0)
{
strcat(arr, &arr);
printf("i. %d strncated %s\n", i, arr);
n--;
}
}
}
}
}
for (int i = 0; i < 10; i++)
{
printf("%c ", arr[i]);
}
printf("\n");
return arr;
}
int main()
{
char s[100] = "3[a2[c]]";
char arr[10] = {0};
decodeString(s, arr);
return 0;
}
here's the output I'm getting, sorry for making this so long
Hi everyone so i got this task to make an adt of non-binary tree which can do traversals. I messed up the structure from the very beginning but I still can do the post-order and pre-order traversal (i don't know if i did it wrong too, but it works). Now i confused how to do the in-order traversal. My code just doesn't work.
This is my data structure
typedef char infotype;
typedef int letak;
typedef struct {
infotype info;
letak parent, firstson, nextsibling;
} node;
typedef node tree;
These are how I initialize each node
void initNode(tree T[], int k, int i)
{
char info;
printf("Input the node name : ");
scanf(" %c", &info);
createNode(T, k, i, info);
}
void createNode(tree T[], int k, int i, char value)
{
int j;
if(i == 0)
{
T[i].info = value;
T[i].firstson = i+1;
}
else
{
T[i].info = value;
T[i].parent = (i-1) / k;
T[i].firstson = (i * k) + 1;
if (i % k != 0)
{
T[i].nextsibling = i+1;
}
else
{
T[i].nextsibling = 0;
}
}
}
and this is how I try to do the in-order traversal
void InOrder(tree T[], int maksimum_array, int maksimum_anak)
{
bool Resmi = true;
int i = 0;
while(i >= 0)
{
if(T[i].firstson < maksimum_array - 1 && Resmi == true)
{
i = T[i].firstson;
}
else
{
if(Resmi == true)
{
printf("%c ", T[i].info);
}
if(i = T[T[i].parent].firstson)
{
printf("%c ", T[T[i].parent].info);
}
if(T[i].nextsibling < maksimum_array - 1 && T[i].nextsibling != 0)
{
i = T[i].nextsibling;
Resmi = true;
}
else
{
i = T[i].parent;
Resmi = false;
}
}
}
}
And this is my main driver :
int main()
{
tree pohon[1000];
int maksimum;
int maksimum_anak;
int level;
int i = 0;
int count = 0;
char cari;
printf("Enter array maximum amount : ");
scanf("%d", &maksimum);
printf("\nEnter maximum child of each node : ");
scanf("%d", &maksimum_anak);
createTree(pohon);
for (i = 0; i < maksimum ; i++)
{
initNode(pohon, maksimum_anak, i);
}
for (i = 0; i < maksimum; i++)
{
printTree(pohon, i, maksimum, maksimum_anak);
}
printf("In Order Traversal : ");
InOrder(pohon, maksimum, maksimum_anak);
}
I've tried another algorithms for the in-order traversal like using recursive. But since i messed up the struct those algorithms just did not work. Thank you before.
if(i = T[T[i].parent].firstson)
Should be
if(i == T[T[i].parent].firstson)
The former assigns to i, the latter compares it.
I came across some problems when building a huffman tree. When building the huffman tree, I use min-heap to implement. And I think the code of min-heap is work well, but when I run the building-huffman-Tree code, the error appears. I have dug into it for a long time, but I have no means to solve it.Hope someone help me sovle my problem.The code is following:
#include <stdio.h>
#include <stdlib.h>
#define MaxSize 100
#define MaxData NULL
// Huffman tree的建树过程用最小堆时因为每次都可以挑出最小的两个元素组成
typedef struct TreeNode {
int weight;
struct TreeNode *left;
struct TreeNode *right;
}HuffmanTree;
typedef struct HeapStruct {
HuffmanTree *Elements[MaxSize+1]; // an array
int Size; // the number of item in array
int Capacity; /* the capacity of heap */
}MinHeap;
MinHeap *Create()
{ // create a empty heap
MinHeap *H;
H = (MinHeap *)malloc(sizeof(MinHeap));
H->Elements[0] = NULL;
H->Size = 0;
H->Capacity = MaxSize;
return H;
}
int isFull(MinHeap *H)
{ // judge the heap full or not
return (H->Size == MaxSize);
}
int isEmpty(MinHeap *H)
{ // judge the heap empty or not
return (H->Size == 0);
}
void Add(MinHeap *H, int item)
{ // add item to the array
if( isFull(H) )
{
printf("the heap is full.\n");
return;
}
HuffmanTree *T;
T = (HuffmanTree *)malloc(sizeof(HuffmanTree));
T->weight = item;
H->Elements[++(H->Size)] = T;
return;
}
void Insert(MinHeap *H, HuffmanTree *item)
{ // insert item
int i;
if( isFull(H) )
{
printf("the heap is full.\n");
return;
}
i = ++(H->Size);
for(; (H->Elements[i/2]->weight)>(item->weight);i/=2)
H->Elements[i] = H->Elements[i/2];
H->Elements[i] = item;
}
HuffmanTree *DeleteMin(MinHeap *H)
{ // delete item of the heap
int Parent, Child;
HuffmanTree *MinValueNode, *tempNode;
if( isEmpty(H) )
{
printf("the heap is empty.\n");
return NULL;
}
MinValueNode = H->Elements[1];
tempNode = H->Elements[H->Size--];
for(Parent=1; Parent*2<=H->Size; Parent=Child)
{
Child = Parent * 2;
if( (Child != H->Size) && (H->Elements[Child]->weight > H->Elements[Child+1]->weight) )
Child++;
if( tempNode->weight <= H->Elements[Child]->weight )
break;
else
H->Elements[Parent] = H->Elements[Child];
}
H->Elements[Parent] = tempNode;
return MinValueNode;
}
void PercDown(MinHeap *H, int i)
{ // adjustment of the heap
int Parent, Child;
HuffmanTree *temp;
temp = H->Elements[i];
for(Parent=i; Parent*2<=H->Size; Parent=Child)
{
Child = Parent * 2;
if( (Child != H->Size) && (H->Elements[Child]->weight > H->Elements[Child+1]->weight) )
Child++; // Child point to the min
if( temp->weight <= H->Elements[Child]->weight )
break;
else
H->Elements[Parent] = H->Elements[Child];
}
H->Elements[Parent] = temp;
}
void BuildMinHeap(MinHeap *H)
{
int i;
for(i=H->Size/2; i>0; i--)
PercDown(H, i);
return;
}
HuffmanTree *Huffman(MinHeap *H)
{ /* Assuming that H->Size weight hava existed in H->Elements[]->weight */
int i;
HuffmanTree *T;
BuildMinHeap( H ); // adjustment
for(i=1; i<H->Size; i++) // merge H->Size-1
{
T = (HuffmanTree *)malloc(sizeof(HuffmanTree));
T->left = DeleteMin( H );
T->right = DeleteMin( H );
T->weight = T->left->weight + T->right->weight;
Insert(H, T);
}
T = DeleteMin( H );
return T;
}
void print_heap(MinHeap *H)
{
if( isEmpty(H) )
{
printf("the heap is empty.\n");
return;
}
for(int i=1; i<=H->Size; i++)
printf("%d ", H->Elements[i]->weight);
printf("\n");
}
void print_tree(HuffmanTree *T)
{
if( T )
{
print_tree(T->left);
printf("%d ", T->weight);
print_tree(T->right);
}
return;
}
int main()
{
MinHeap *heap;
HuffmanTree *HT, *T;
heap = Create();
int x;
printf("please input data:\n");
scanf("%d", &x);
while( x )
{
Add(heap, x);
scanf("%d", &x);
}
printf("original items:\n");
print_heap( heap );
printf("the item number of heap%d\n", heap->Size);
BuildMinHeap(heap);
print_heap( heap );
HT = DeleteMin( heap );
printf("删除的结点的值为%d\n", HT->weight);
print_heap( heap );
HT = Huffman( heap );
print_tree( HT );
return 0;
}
So I'm having trouble with Dijkstra's algorithm (src to dest). I looked at other answers and could not find the solution to my problem. I have used an adjacency list, thus I have a list for vertices, and each vertex has it's own edge list. My problem arises when I have a node that is unreachable. Specifically, it never gets visited thus I'm stuck in my allNotComp while loop. Can anyone help me with a solution? Code is below.
#include <stdlib.h>
#include <stdio.h>
int INFINITY = 9999;
struct edge
{
int vertexIndex;
int vertexWeight;
struct edge *edgePtr;
} edge;
struct vertex
{
int vertexKey;
struct edge *edgePtr;
struct vertex *vertexPtr;
}vertex;
struct vertex *Start = NULL;
void insertEdge(int vertex, int vertex2, int vertexWeight);
void insertVertex(int vertexKey);
int allNotComp(int comp[], int size);
void printPath(int prev[], int src, int dest, int size);
void dijkstra(int src, int size, int dest);
int cost(int curr, int i);
int main(int argc, char * argv[]) {
int k = 1;
int numVertices = atoi(argv[2]);
char* source = argv[3];
char* destination = argv[4];
int src = atoi(argv[3]);
int dest = atoi(argv[4]);
Start = &vertex;
Start->vertexKey = 0;
Start->vertexPtr = NULL;
Start->edgePtr = NULL;
int m = 0;
int flag = 0;
int flag2 = 0;
for(m = 0; m < numVertices; m++){
if(src == m) {
flag = 1;
}
if(dest == m) {
flag2 = 1;
}
}
if(!(flag && flag2)) {
printf("%s ", "ERROR: Src and/or Dest not valid.\n");
exit(0);
}
while(k < numVertices) {
insertVertex(k);
k++;
}
FILE *f = fopen(argv[1], "r");
int numbers[numVertices][numVertices];
char ch;
int i = 0;
int j = 0;
for(m = 0; m < numVertices*numVertices; m++) {
fscanf(f, "%d", &(numbers[i][j]));
j=j+1;
if(j == numVertices) {
i=i+1;
j=0;
}
}
for(i=0;i<numVertices;i++) {
for(j=0;j<numVertices;j++) {
if(i == j && numbers[i][j] != 0) {
printf("%s", "ERROR: All diagonals must be zero.\n");
exit(0);
}
if(i != j) {
insertEdge(i, j, numbers[i][j]);
}
}
}
dijkstra(src, numVertices, dest);
}
void insertEdge(int vertex, int vertex2, int vertexWeight)
{
if(vertexWeight == -1) return;
struct vertex *traverse;
if(vertex == Start->vertexKey) {
traverse = Start;
}
else {
while(traverse->vertexKey != vertex) {
traverse = traverse->vertexPtr;
}
}
struct edge *e,*e1,*e2;
e=traverse->edgePtr;
while(e&& e->edgePtr)
{
e=e->edgePtr;
}
e1=(struct edge *)malloc(sizeof(*e1));
e1->vertexIndex=vertex2;
e1->vertexWeight = vertexWeight;
e1->edgePtr=NULL;
if(e)
e->edgePtr=e1;
else
traverse->edgePtr=e1;
}
void insertVertex(int vertexKey) {
struct vertex *v, *v1, *v2;
v = Start->vertexPtr;
while(v && v->vertexPtr) {
v=v->vertexPtr;
}
v1=(struct vertex *)malloc(sizeof(*v1));
v1->vertexKey = vertexKey;
v1->vertexPtr = NULL;
v1->edgePtr = NULL;
if(v) {
v->vertexPtr = v1;
}
else {
Start->vertexPtr = v1;
}
}
void dijkstra(int src, int size, int dest) {
int comp[size];
int dist[size];
int prev[size];
int i;
for(i = 0; i<size; i++) {
comp[i] = 0;
dist[i] = INFINITY;
prev[i] = -1;
}
comp[src] = 1;
dist[src] = 0;
prev[src] = src;
int curr = src;
int k;
int minDist;
int newDist;
while(allNotComp(comp, size)) {
minDist = INFINITY;
for(i = 0; i<size;i++) {
if(comp[i] == 0) {
newDist = dist[curr] + cost(curr, i);
if(newDist < dist[i]) {
dist[i] = newDist;
prev[i] = curr; }
if(dist[i] < minDist) {
minDist = dist[i];
k=i; }
}
}
curr = k;
comp[curr] = 1;
}
if(dist[dest] < INFINITY) {
printPath(prev, src, dest, size);
printf(":%d\n", dist[dest]);
} else {
printf("%s\n", "NO PATH EXISTS BETWEEN THE TWO VERTICES!");
}
}
int allNotComp(int comp[], int size) {
int i;
for(i = 0; i < size; i++) {
if(comp[i] == 0) {
return 1;
}
}
return 0;
}
int cost(int curr, int i) {
struct vertex *travel;
struct edge *traverse;
travel = Start;
while(travel->vertexPtr != NULL) {
if(travel->vertexKey != curr) {
travel = travel->vertexPtr;
}
else{
break;
}
}
traverse = travel->edgePtr;
while(traverse->edgePtr != NULL) {
if(traverse->vertexIndex != i) {
traverse = traverse->edgePtr;
}
else{
break;
}
}
if(traverse->vertexIndex != i) {
return INFINITY;
}
return traverse->vertexWeight;
}
void printPath(int prev[], int src, int dest, int size) {
if(src == dest) {
printf("%d", src);
}
else {
printPath(prev, src, prev[dest], size);
printf("-%d", dest);
}
}
Although an unreachable node never gets visited, this situation can be detected. If the dists of all unvisited nodes are INFINITY, this means all remaining nodes are unreachable, and you should end the loop.
i have one error in that code for parsing expressions, it says
"146 C:\Dev-Cpp\z.c conflicting types for 'show_tree' 111
C:\Dev-Cpp\z.c previous implicit declaration of 'show_tree' was here"
help please...
#include<stdio.h>
#include<stdlib.h>
int getOperatorPosition(char);
#define node struct tree1
int matrix[5][5]=
{
{1,0,0,1,1},
{1,1,0,1,1},
{0,0,0,2,3},
{1,1,3,1,1},
{0,0,0,3,2}
};
int tos=-1;
void matrix_value(void);
//node create_node(char,*node);void show_tree( node *);
int isOperator(char);
struct tree1
{
char data;
node *lptr;
node *rptr;
}
*first;
struct opr
{
char op_name;
node *t;
}
oprate[50];
char cur_op[5]= {'+','*','(',')','['};
char stack_op[5]= {'+','*','(',')',']'};
int main()
{
char exp[10];
int ssm=0,row=0,col=0;
node *temp;
// clrscr();
printf("Enter Exp : ");
scanf("%s",exp);
matrix_value();
while(exp[ssm] != '\0')
{
if(ssm==0)
{
tos++;
oprate[tos].op_name = exp[tos];
}
else
{
if(isOperator(exp[ssm]) == -1)
{
oprate[tos].t = (node*) malloc(sizeof(node));
oprate[tos].t->data = exp[ssm];
oprate[tos].t->lptr = '\0';
oprate[tos].t->rptr = '\0';
}
else
{
row = getOperatorPosition(oprate[tos].op_name);
col = getOperatorPosition(exp[ssm]);
if(matrix[row][col] == 0)
{
tos++;
oprate[tos].op_name = exp[ssm];
}
else if(matrix[row][col] == 1)
{
temp = (node*) malloc(sizeof(node));
temp->data = oprate[tos].op_name;
temp->lptr = (oprate[tos-1].t);
temp->rptr = (oprate[tos].t);
tos--;
oprate[tos].t = temp;
ssm--;
}
else if(matrix[row][col] == 2)
{
//temp = (node*) malloc (sizeof(node));
temp = oprate[tos].t;
tos--;
oprate[tos].t = temp;
}
else if(matrix[row][col] == 3)
{
printf("\nExpression is Invalid...\n");
printf("%c %c can not occur simultaneously\n",oprate[tos].op_name,exp[ssm]);
break;
}
}
}
ssm++;
}
printf("show tree \n\n\n");
show_tree(oprate[tos].t);
printf("Over");
}
int isOperator(char c)
{
int i=0;
for(i=0; i<5; i++)
{
if(c==cur_op[i] || c==stack_op[i])
{
break;
}
}
if(i==5)
{
return (-1);
}
else
{
return i;
}
}
int getOperatorPosition(char c)
{
int i;
for(i=0; i<5; i++)
{
if(c==cur_op[i] || c==stack_op[i])
{
break;
}
}
return i;
}
void show_tree(node *start)
{
if(start->lptr != NULL)
{
show_tree(start->lptr);
}
if(start->rptr != NULL)
{
show_tree(start->rptr);
}
printf("%c \n",start->data);
}
void matrix_value(void)
{
int i,j;
printf("OPERATOR PRECEDENCE MATRIX\n");
printf("==========================\n");
for(i=0; i<5; i++)
{
printf("%c ",stack_op[i]);
}
printf("\n");
for(i=0; i<5; i++)
{
printf("%c ",cur_op[i]);
for(j=0; j<5; j++)
{
if(matrix[i][j] == 0)
{
printf("< ");
}
else if(matrix[i][j] == 1)
{
printf("> ");
}
else if(matrix[i][j] == 2)
{
printf("= ");
}
else if(matrix[i][j] == 3)
{
printf(" ");
}
}
printf("\n");
}
}
declare your show_tree function before main.
i.e. before struct tree1:
int isOperator(char );
void show_tree(node *start);
struct tree1
{
char data;
node *lptr;
node *rptr;
}
*first;
...