-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
983cd6a
commit 0bc8a84
Showing
10 changed files
with
384 additions
and
44 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
type | ||
dataT { | ||
int a; | ||
dataT b; | ||
} | ||
endtype | ||
|
||
decl | ||
dataT arr[5], func(dataT *arg), h; | ||
enddecl | ||
|
||
dataT func(dataT *arg) | ||
{ | ||
begin | ||
*arg = alloc(); | ||
h = *arg; | ||
h.a = 8; | ||
h.b = h; | ||
return null; | ||
end | ||
} | ||
|
||
int main() | ||
{ | ||
decl | ||
dataT *ptr, px; | ||
enddecl | ||
|
||
begin | ||
initialize(); | ||
arr[0] = alloc(); | ||
arr[1] = alloc(); | ||
arr[2] = alloc(); | ||
arr[3] = alloc(); | ||
arr[4] = alloc(); | ||
|
||
ptr = &arr[1]; | ||
px = *ptr; | ||
px.a = 5; | ||
write(px.a); | ||
write(func(ptr)); | ||
px = arr[1]; | ||
write(px.b.b.b.b.b.a); | ||
arr[0] = *ptr; | ||
if(arr[0] == arr[1]) then | ||
write("equality works"); | ||
endif; | ||
if(arr[0] == "no") then | ||
write ("equality no work"); | ||
endif; | ||
|
||
return 0; | ||
end | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
type | ||
bst{ | ||
int a; | ||
bst left; | ||
bst right; | ||
} | ||
endtype | ||
|
||
decl | ||
int in,opt; | ||
bst insert(bst h, int key); | ||
int inOrder(bst h); | ||
int preOrder(bst h); | ||
int postOrder(bst h); | ||
enddecl | ||
|
||
bst insert(bst h, int key) | ||
{ | ||
|
||
begin | ||
if (h == null) then | ||
h = alloc(); | ||
h.a = key; | ||
h.left = null; | ||
h.right = null; | ||
|
||
else if (key < h.a) then | ||
h.left = insert(h.left, key); | ||
|
||
else if (key > h.a) then | ||
h.right = insert(h.right, key); | ||
endif; | ||
endif; | ||
endif; | ||
|
||
return h; | ||
end | ||
} | ||
|
||
int inOrder(bst h){ | ||
|
||
begin | ||
|
||
if(h!=null) then | ||
|
||
in=inOrder(h.left); | ||
write(h.a); | ||
in=inOrder(h.right); | ||
endif; | ||
return 1; | ||
end | ||
} | ||
|
||
int preOrder(bst h){ | ||
|
||
begin | ||
|
||
if(h!=null) then | ||
write(h.a); | ||
in=preOrder(h.left); | ||
|
||
in=preOrder(h.right); | ||
endif; | ||
return 1; | ||
end | ||
} | ||
|
||
int postOrder(bst h){ | ||
|
||
begin | ||
|
||
if(h!=null) then | ||
|
||
in=postOrder(h.left); | ||
|
||
in=postOrder(h.right); | ||
write(h.a); | ||
endif; | ||
return 1; | ||
end | ||
} | ||
|
||
int main() | ||
{ | ||
decl | ||
int val,flag; | ||
bst Root; | ||
enddecl | ||
|
||
begin | ||
val = initialize(); | ||
Root = null; | ||
|
||
read(val); | ||
|
||
while(val!=0) do | ||
Root = insert(Root,val); | ||
read(val); | ||
endwhile; | ||
|
||
in = inOrder(Root); | ||
in = preOrder(Root); | ||
in = postOrder(Root); | ||
|
||
return 9; | ||
end | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
type | ||
node | ||
{ | ||
int d; | ||
int s; | ||
int t; | ||
} | ||
endtype | ||
|
||
decl | ||
node y,z,gcd(int a,int b); | ||
enddecl | ||
|
||
node gcd(int a,int b) | ||
{ | ||
decl | ||
int q,r,temp; | ||
enddecl | ||
|
||
begin | ||
if(b==0) then | ||
y.d = a; | ||
y.s = 1; | ||
y.t = 0; | ||
else | ||
q = a/b; | ||
r = a%b; | ||
z = gcd(b,r); | ||
temp = z.s; | ||
y.s = z.t; | ||
y.t = temp - (q*z.t); | ||
endif; | ||
|
||
return y; | ||
end | ||
} | ||
|
||
int main() | ||
{ | ||
decl | ||
node res; | ||
int a,b,c; | ||
enddecl | ||
|
||
begin | ||
c = initialize(); | ||
y = alloc(); | ||
read(a); | ||
read(b); | ||
res = gcd(a,b); | ||
write(res.d); | ||
write(res.s); | ||
write(res.t); | ||
|
||
return 0; | ||
end | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
type | ||
node | ||
{ | ||
int d; | ||
int s; | ||
int t; | ||
} | ||
List | ||
{ | ||
int a; | ||
int b; | ||
node g; | ||
List next; | ||
} | ||
endtype | ||
decl | ||
node y,z; | ||
List head; | ||
int insert(int a,int b,node g); | ||
node gcd(int m,int n); | ||
enddecl | ||
int insert(int a,int b,node g) | ||
{ | ||
decl | ||
List p,q; | ||
node temp; | ||
enddecl | ||
begin | ||
p=alloc(); | ||
p.a=a; | ||
p.b=b; | ||
temp=alloc(); | ||
temp.d=g.d; | ||
temp.s=g.s; | ||
temp.t=g.t; | ||
p.g=temp; | ||
if (head== null) then | ||
p.next=null; | ||
head=p; | ||
else | ||
p.next=head; | ||
head=p; | ||
endif; | ||
return 0; | ||
end | ||
} | ||
|
||
node gcd(int m,int n){ | ||
|
||
decl | ||
int q,r,temp; | ||
enddecl | ||
|
||
begin | ||
if(n==0) then | ||
y.d = m; | ||
y.s = 1; | ||
y.t = 0; | ||
else | ||
q = m/n; | ||
r = m-q*n; | ||
z = gcd(n,r); | ||
temp = z.s; | ||
y.s = z.t; | ||
y.t = temp - (q*z.t); | ||
endif; | ||
temp=insert(m,n,y); | ||
return y; | ||
end | ||
} | ||
|
||
int main() | ||
{ | ||
decl | ||
int a,b,c; | ||
node res; | ||
enddecl | ||
|
||
begin | ||
c = initialize(); | ||
y = alloc(); | ||
read(a); | ||
read(b); | ||
head=null; | ||
res = gcd(a,b); | ||
write(res.d); | ||
write(res.s); | ||
write(res.t); | ||
write("stack"); | ||
while(head!= null) do | ||
write(head.a); | ||
write(head.b); | ||
write(head.g.d); | ||
write(head.g.s); | ||
write(head.g.t); | ||
head=head.next; | ||
write("next"); | ||
endwhile; | ||
return 0; | ||
end | ||
} |
Oops, something went wrong.