Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
sorted-tree-c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
software-security
sorted-tree-c
Merge requests
!1
Final commit
Code
Review changes
Check out branch
Download
Patches
Plain diff
Closed
Final commit
ss-group-5/sorted-tree-c:fresh-start
into
main
Overview
1
Commits
11
Pipelines
0
Changes
4
Closed
Logmans, J.H. (Job, Student M-CS)
requested to merge
ss-group-5/sorted-tree-c:fresh-start
into
main
1 year ago
Overview
1
Commits
11
Pipelines
0
Changes
4
Expand
Rewrite of our original try
0
0
Merge request reports
Viewing commit
40ab149e
Prev
Next
Show latest version
4 files
+
49
−
10
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
40ab149e
Fixed fancy print messing up tests
· 40ab149e
Job Logmans
authored
1 year ago
main/src/main.c
+
64
−
42
Options
@@ -3,18 +3,22 @@
#include
<string.h>
#include
"main.h"
#include
"tree.h"
#define INPUTSIZE 20
// You are allowed to change anything about this function to fix it
int
main
()
{
char
*
commandBuffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
20
);
int
main
()
{
char
*
commandBuffer
=
(
char
*
)
malloc
(
sizeof
(
char
)
*
INPUTSIZE
);
Tree
*
tree
=
tree_create
();
for
(;;)
{
fgets
(
commandBuffer
,
20
,
stdin
);
for
(;;)
{
fgets
(
commandBuffer
,
INPUTSIZE
,
stdin
);
// Quit on EOF or 'q'
if
(
feof
(
stdin
)
||
commandBuffer
==
"q"
){
if
(
feof
(
stdin
)
||
commandBuffer
==
"q"
)
{
break
;
}
@@ -32,47 +36,56 @@ int main() {
* You are allowed to change anything about this function to fix it
* @param command The command string to handle
*/
Tree
*
handleString
(
char
command
[],
Tree
*
tree
){
if
(
command
==
NULL
){
Tree
*
handleString
(
char
command
[],
Tree
*
tree
)
{
if
(
command
==
NULL
)
{
fprintf
(
stderr
,
"Invalid command; null pointer
\n
"
);
return
tree
;
}
switch
(
command
[
0
]){
case
'i'
:
insert
(
command
,
tree
);
break
;
case
'e'
:
erase
(
command
,
tree
);
break
;
case
'c'
:
check
(
command
,
tree
);
break
;
case
'p'
:
tree_print
(
tree
,
1
);
break
;
case
'x'
:
tree_delete
(
tree
);
return
NULL
;
default:
fprintf
(
stderr
,
"Invalid command string: %s
\n
"
,
command
);
break
;
switch
(
command
[
0
])
{
case
'i'
:
insert
(
command
,
tree
);
break
;
case
'e'
:
erase
(
command
,
tree
);
break
;
case
'c'
:
check
(
command
,
tree
);
break
;
case
'p'
:
tree_print
(
tree
,
1
);
break
;
case
'o'
:
tree_fancy_print
(
tree
,
1
);
break
;
case
'x'
:
tree_delete
(
tree
);
break
;
default:
fprintf
(
stderr
,
"Invalid command string: %s
\n
"
,
command
);
break
;
}
return
tree
;
}
// You are allowed to change anything about this function to tix it
Tree
*
insert
(
char
*
command
,
Tree
*
tree
)
{
Tree
*
insert
(
char
*
command
,
Tree
*
tree
)
{
int
age
;
char
*
name
=
malloc
(
sizeof
(
char
)
*
20
);
char
*
name
=
malloc
(
sizeof
(
char
)
*
INPUTSIZE
);
if
(
2
!=
sscanf
(
command
,
"i %d %s"
,
&
age
,
name
)){
if
(
2
!=
sscanf
(
command
,
"i %d %s"
,
&
age
,
name
))
{
fprintf
(
stderr
,
"Failed to parse insert command: not enough parameters filled
\n
"
);
return
NULL
;
}
if
(
tree
==
NULL
){
if
(
tree
==
NULL
)
{
tree
=
tree_create
();
}
@@ -81,29 +94,38 @@ Tree* insert(char* command, Tree* tree) {
}
// You are allowed to change anything about this function to fix it
void
erase
(
char
*
command
,
Tree
*
tree
)
{
void
erase
(
char
*
command
,
Tree
*
tree
)
{
int
age
;
char
*
name
=
malloc
(
sizeof
(
char
)
*
20
);
char
*
name
=
malloc
(
sizeof
(
char
)
*
INPUTSIZE
);
if
(
2
!=
sscanf
(
command
,
"e %d %s"
,
&
age
,
name
)){
if
(
2
!=
sscanf
(
command
,
"e %d %s"
,
&
age
,
name
))
{
fprintf
(
stderr
,
"Failed to parse erase command: not enough parameters filled
\n
"
);
}
tree_erase
(
tree
,
age
,
name
);
}
// You are allowed to change anything about this function to fix it
void
check
(
char
*
command
,
Tree
*
tree
)
{
void
check
(
char
*
command
,
Tree
*
tree
)
{
int
age
;
char
*
name
=
malloc
(
sizeof
(
char
)
*
20
);
char
*
name
=
malloc
(
sizeof
(
char
)
*
INPUTSIZE
);
if
(
2
!=
sscanf
(
command
,
"c %d %s"
,
&
age
,
name
)){
if
(
2
!=
sscanf
(
command
,
"c %d %s"
,
&
age
,
name
))
{
fprintf
(
stderr
,
"Failed to parse check command
\n
"
);
}
Node
*
result
=
tree_find
(
tree
,
age
,
name
);
if
(
result
){
printf
(
"y
\n
"
);
}
else
{
printf
(
"n
\n
"
);
else
{
Node
*
result
=
tree_find
(
tree
,
age
,
name
);
if
(
result
)
{
printf
(
"y
\n
"
);
}
else
{
printf
(
"n
\n
"
);
}
}
}
Loading