Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
contact_manager
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD 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
SECOND
java
contact_manager
Commits
8949f74a
Commit
8949f74a
authored
2 years ago
by
jonas.stirnema
Browse files
Options
Downloads
Patches
Plain Diff
Add family name sorted ok
parent
854aed3a
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/DynArray.java
+57
-10
57 additions, 10 deletions
src/DynArray.java
src/Main.java
+12
-7
12 additions, 7 deletions
src/Main.java
with
69 additions
and
17 deletions
src/DynArray.java
+
57
−
10
View file @
8949f74a
...
@@ -31,6 +31,53 @@ public class DynArray {
...
@@ -31,6 +31,53 @@ public class DynArray {
// }
// }
// }
// }
public
void
insert
(
Contact
a
,
int
index
)
{
//this.show_it();
Contact
[]
new_arr
=
new
Contact
[++
this
.
capacity
];
// Before index
for
(
int
j
=
0
;
j
<
index
;
j
++)
{
new_arr
[
j
]
=
this
.
array
[
j
];
}
// Add the new item
new_arr
[
index
]
=
a
;
this
.
size
++;
// Add the rest of the items
for
(
int
j
=
index
;
j
<
this
.
size
;
j
++)
{
new_arr
[
j
+
1
]
=
this
.
array
[
j
];
}
this
.
array
=
new_arr
;
// Copy pointer
}
// SORTED INSERT
// GO TRHOUGH THE ARRAY
// CHECK IF THE NEXT CONTACT FNAME AND NAME IS GRAMATICALLY BIGGER
// IF IT IS, CREATE A NEW ARRAY, ADD ALL THE PREVIOUS VALUES
// ADD THE VALUE TO INSERT, ADD THE REST OF THE VALUES
public
void
insert
(
Contact
a
)
{
//System.err.println("Size = " + size);
for
(
int
i
=
0
;
i
<
this
.
size
;
i
++)
{
// Check if a.fname should be before ith item
// Order by fname
if
(
a
.
getFname
().
compareToIgnoreCase
(
this
.
array
[
i
].
getFname
())
<
0
)
{
// Should be before when compared by fname
//System.err.println("In if");
this
.
insert
(
a
,
i
);
return
;
}
}
//System.err.println("Appenned");
this
.
append
(
a
);
}
public
void
append
(
Contact
...
a
)
{
public
void
append
(
Contact
...
a
)
{
make_sure_size
(
a
);
// REALLOC IF NEEDED
make_sure_size
(
a
);
// REALLOC IF NEEDED
this
.
size
+=
a
.
length
;
this
.
size
+=
a
.
length
;
...
@@ -63,17 +110,17 @@ public class DynArray {
...
@@ -63,17 +110,17 @@ public class DynArray {
}
}
}
}
//
public void make_sure_size(Contact a) {
public
void
make_sure_size
(
Contact
a
)
{
//
if ((this.size + 1) > this.capacity) // Overflow?
if
((
this
.
size
+
1
)
>
this
.
capacity
)
// Overflow?
//
{
{
//
// Realloc new array
// Realloc new array
//
this.capacity *= 2;
this
.
capacity
*=
2
;
//
Contact[] new_arr = new Contact[this.capacity];
Contact
[]
new_arr
=
new
Contact
[
this
.
capacity
];
//
copy_content(this.array, new_arr);
copy_content
(
this
.
array
,
new_arr
);
//
this.array = new_arr; // Copy pointer
this
.
array
=
new_arr
;
// Copy pointer
//
}
}
//
}
}
public
void
show_it
()
{
public
void
show_it
()
{
System
.
out
.
println
(
this
.
toString
());
System
.
out
.
println
(
this
.
toString
());
...
...
This diff is collapsed.
Click to expand it.
src/Main.java
+
12
−
7
View file @
8949f74a
...
@@ -11,15 +11,20 @@ public class Main {
...
@@ -11,15 +11,20 @@ public class Main {
"Eboueur"
);
"Eboueur"
);
Contact
c2
=
new
Contact
();
Contact
c2
=
new
Contact
();
Contact
c3
=
new
Contact
(
"fnamekek"
,
"joseph"
);
Contact
c3
=
new
Contact
(
"fnamekek"
,
"joseph"
);
Contact
c4
=
new
Contact
(
"igueule"
,
"monvieux"
);
// c1.show();
Contact
c5
=
new
Contact
(
"monkey"
,
"Lucio"
);
// c2.show();
// c3.show();
// System.out.println(c1.toShortString());
// c2.showShort();
DynArray
contacts
=
new
DynArray
();
DynArray
contacts
=
new
DynArray
();
contacts
.
append
(
c1
,
c2
,
c3
);
//contacts.append(c1, c2, c3);
//contacts.insert(c4, 1);
contacts
.
insert
(
c1
);
contacts
.
insert
(
c2
);
contacts
.
insert
(
c3
);
contacts
.
insert
(
c4
);
contacts
.
insert
(
c5
);
System
.
out
.
println
(
contacts
.
toString
());
System
.
out
.
println
(
contacts
.
toString
());
}
}
}
}
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