-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllclient.c
More file actions
executable file
·206 lines (138 loc) · 2.83 KB
/
llclient.c
File metadata and controls
executable file
·206 lines (138 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* RPC client for simple addition example */
/*
* Name :sharad Dixit
* Institute:Indian institute of information technology
*/
#include <stdio.h>
#include <stdlib.h>
#include "ll.h"
/* Created for us by rpcgen - has everything we need ! */
void display(tree*st,int level)
{
int i;
if(st)
{
display(st->right,level+1);
printf("\n");
for(i=0;i<level;i++)
printf(" ");
printf("%d",st->x);
display(st->left,level+1);
}
}
//printing the inorder of the tree
void inorder(tree * root)
{
static int count=0;
if(root!=NULL)
{
count=1;
inorder(root->left);
printf("->%d",root->x);
inorder(root->right);
}
else if((root==NULL)&&(count==0))
{
printf("Tree is null");
}
}
//printing the preorder of the tree
void preorder(tree * root)
{
static int count=0;
if(root!=NULL)
{
count=1;
printf("->%d",root->x);
preorder(root->left);
preorder(root->right);
}
else if((root==NULL)&&(count==0))
{
printf("Tree is null");
}
}
//printing the postorder of the tree
void postorder(tree * root)
{
static int count=0;
if(root!=NULL)
{
count=1;
postorder(root->left);
postorder(root->right);
printf("->%d",root->x);
}
else if((root==NULL)&&(count==0))
{
printf("Tree is null");
}
}
//printing the nodes given in input
void printnums( foo *f)
{
printf(" the entered nodes are:::");
while (f) {
printf("%d ",f->x);
f=f->next;
}
printf("\n");
}
void print_inorder( foo *head, CLIENT *clnt)
{
tree *result;
result = in_1(head, clnt);
if (result == NULL)
{
clnt_perror(clnt, "call failed");
return;
}
display(result,1);
printf("\n\n\n");
printf("preorder of the tree::\n");
preorder(result);
printf("\n");
printf("inorder of the tree::\n");
inorder(result);
printf("\n");
printf("postorder of the tree::\n");
postorder(result);
printf("\n");
}
int main( int argc, char *argv[])
{
CLIENT *clnt;
int n,i;
foo *f;
foo *head;
foo *prev;
if (argc<3)
{
fprintf(stderr,"Usage: %s hostname num1 num2 ...\n",argv[0]);
exit(0);
}
/* Create a CLIENT data structure that reference the RPC
procedure SIMP_PROG, version SIMP_VERSION running on the
host specified by the 1st command line arg. */
clnt = clnt_create(argv[1], LL_PROG, LL_VERSION, "udp");
/* Make sure the create worked */
if (clnt == (CLIENT *) NULL)
{
clnt_pcreateerror(argv[1]);
exit(1);
}
n = argc-2;
f = head = (foo *) malloc(sizeof(foo));
for (i=0;i<n;i++)
{
f->x = atoi(argv[i+2]);
f->next = (foo *) malloc(sizeof(foo));
prev=f;
f = f->next;
}
free(prev->next);
prev->next=NULL;
printnums(head);
print_inorder(head,clnt);
return(0);
}