Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
alg3-trab1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Eduardo Machado
alg3-trab1
Commits
5b4e3a5a
Commit
5b4e3a5a
authored
9 years ago
by
Eduardo Machado
Browse files
Options
Downloads
Patches
Plain Diff
atualizado
parent
7b80fde8
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/bst_lib.h
+2
-7
2 additions, 7 deletions
lib/bst_lib.h
src/bst_lib.cpp
+37
-14
37 additions, 14 deletions
src/bst_lib.cpp
src/main.cpp
+28
-0
28 additions, 0 deletions
src/main.cpp
with
67 additions
and
21 deletions
lib/bst_lib.h
+
2
−
7
View file @
5b4e3a5a
...
@@ -15,10 +15,5 @@ class Node{
...
@@ -15,10 +15,5 @@ class Node{
void
setLeftNode
(
Node
*
newLeftNode
);
void
setLeftNode
(
Node
*
newLeftNode
);
void
setRightNode
(
Node
*
newRightNode
);
void
setRightNode
(
Node
*
newRightNode
);
void
setFatherNode
(
Node
*
newRatherNode
);
void
setFatherNode
(
Node
*
newRatherNode
);
void
printInOrder
();
int
getKey
();
};
char
getTruck
();
Node
*
getLeftNode
();
Node
*
getRightNode
();
Node
*
getFatherNode
();
}
This diff is collapsed.
Click to expand it.
src/bst_lib.cpp
+
37
−
14
View file @
5b4e3a5a
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
// 2015
// 2015
#include
<iostream>
#include
<iostream>
#include
"bst_lib.h"
#include
"
lib/
bst_lib.h"
using
namespace
std
;
using
namespace
std
;
...
@@ -22,28 +22,51 @@ void Node::setLeftNode(Node *newLeftNode){
...
@@ -22,28 +22,51 @@ void Node::setLeftNode(Node *newLeftNode){
void
Node
::
setRightNode
(
Node
*
newRightNode
){
void
Node
::
setRightNode
(
Node
*
newRightNode
){
rightNode
=
newRightNode
;
rightNode
=
newRightNode
;
}
}
void
Node
::
setFatherNode
(
Node
*
newFatherNode
){
void
Node
::
setFatherNode
(
Node
*
newFatherNode
){
fatherNode
=
newFatherNode
;
fatherNode
=
newFatherNode
;
}
}
int
Node
::
getKey
(){
void
Node
::
printInOrder
(){
return
(
this
->
key
);
if
(
this
->
leftNode
!=
NULL
){
this
->
leftNode
.
printInOrder
()
}
}
std
::
cout
<<
" "
<<
this
->
truck
<<
this
->
key
<<
" "
<<
std
::
endl
;
char
Node
::
getTruck
(
){
if
(
this
->
rightNode
!=
NULL
){
return
(
this
->
truck
);
this
->
rightNode
.
printInOrder
(
);
}
}
Node
*
Node
::
getLeftNode
(){
return
(
this
->
leftNode
);
}
}
Node
*
Node
::
getRightNode
(){
// Funções de manipulação da árvore
return
(
this
->
rightNode
);
Node
*
createNode
(
int
key
,
char
truck
){
Node
*
newNode
=
malloc
(
sizeof
(
Node
));
newNode
.
setkey
(
key
);
newNode
.
setTruck
(
truck
);
newNode
.
setLeftNode
(
NULL
);
newNode
.
setRightNode
(
NULL
);
newNode
.
setFatherNode
(
NULL
);
return
(
newNode
);
}
}
Node
*
Node
::
getFatherNode
(){
void
insertNode
(
Node
*
root
,
int
key
,
char
truck
){
return
(
this
->
fatherNode
);
if
(
root
==
NULL
){
root
=
createNode
(
key
,
truck
);
}
else
if
(
root
.
key
>
key
){
insertNode
(
root
->
leftNode
);
}
else
if
(
root
.
key
<
key
){
insertNode
(
root
->
rightNode
);
}
}
}
// Funções de manipulação da árvore
Node
*
binarySearch
(
Node
*
root
,
int
key
){
if
(
root
.
key
==
key
){
return
(
root
);
}
else
if
(
root
.
key
>
key
){
return
(
binarySearch
(
root
->
leftNode
));
}
else
if
(
root
.
key
<
key
){
return
(
binarySearch
(
root
->
rightNode
));
}
else
if
(
root
==
NULL
){
return
(
NULL
);
}
}
This diff is collapsed.
Click to expand it.
src/main.cpp
0 → 100644
+
28
−
0
View file @
5b4e3a5a
// Implementado por Eduardo Machado
// 2015
#include
<iostream>
#include
"lib/bst_lib.h"
using
namespace
std
;
int
main
(
int
argc
,
char
*
argv
[])
{
Node
*
tree
=
NULL
;
char
*
input
,
auxTruck
;
int
auxKey
;
while
(
1
)
{
std
::
cin
>>
input
;
if
(
strcmp
(
input
,
"insert"
)
==
0
){
std
::
cin
>>
auxTruck
;
std
::
cin
>>
auxKey
;
if
(
binarySearch
(
tree
,
auxKey
)
!=
NULL
){
insertNode
(
tree
,
auxKey
,
auxTruck
);
}
}
else
if
(
strcmp
(
input
,
"print"
)
==
0
){
tree
.
printInOrder
;
}
}
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment