Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
Inf3
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
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
Marcel Kehrberg
Inf3
Commits
9c717409
Commit
9c717409
authored
2 years ago
by
Michael Ghebremussie
Browse files
Options
Downloads
Patches
Plain Diff
added Comments and changed the Function- and Variable names.
parent
3cbe0809
No related branches found
No related tags found
1 merge request
!2
added Comments and changed the Function- and Variable names.
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
Aufgabe3/ConsoleApplication1/Buffer.cs
+26
-37
26 additions, 37 deletions
Aufgabe3/ConsoleApplication1/Buffer.cs
with
26 additions
and
37 deletions
Aufgabe3/ConsoleApplication1/Buffer.cs
+
26
−
37
View file @
9c717409
...
@@ -4,70 +4,59 @@ using System.Threading;
...
@@ -4,70 +4,59 @@ using System.Threading;
namespace
ConsoleApplication1
namespace
ConsoleApplication1
{
{
/// <summary>
/// Creating a Class Buffer that contains a Queue that represent the "Parking lot".
/// The Queue is limited by the size that can manually be setted
/// </summary>
public
class
Buffer
public
class
Buffer
{
{
private
Queue
<
Car
>
carQueue
;
private
Queue
<
Car
>
_
carQueue
;
private
int
size
=
10
;
private
int
_
size
=
10
;
private
Mutex
mutex
;
private
Mutex
_
mutex
;
// Constructor initialized with a Mutex and a Queue.
public
Buffer
()
public
Buffer
()
{
{
mutex
=
new
Mutex
();
_
mutex
=
new
Mutex
();
carQueue
=
new
Queue
<
Car
>();
_
carQueue
=
new
Queue
<
Car
>();
}
}
public
void
push
(
Car
c
)
// This function adds a Car Object into the Queue.
public
void
Push
(
Car
c
)
{
{
if
(
carQueue
.
Count
==
size
)
// Check whether the Queue is full and throws an Exception if so.
if
(
_carQueue
.
Count
==
_size
)
{
{
throw
new
Exception
(
"Buffer full"
);
throw
new
Exception
(
"Buffer full"
);
}
}
carQueue
.
Enqueue
(
c
);
_
carQueue
.
Enqueue
(
c
);
}
}
public
Car
pop
()
// Removes a Car Object from the Queue and returns the Queue.
public
Car
Pop
()
{
{
if
(
carQueue
.
Count
==
0
)
if
(
_
carQueue
.
Count
==
0
)
{
{
throw
new
Exception
(
"Buffer empty"
);
throw
new
Exception
(
"Buffer empty"
);
}
}
return
carQueue
.
Dequeue
();
return
_
carQueue
.
Dequeue
();
}
}
public
bool
full
()
// Check if the Queue is full.
public
bool
Full
()
{
{
bool
isFull
=
false
;
return
_carQueue
.
Count
==
_size
;
if
(
carQueue
.
Count
==
size
)
{
isFull
=
true
;
}
return
isFull
;
}
}
public
bool
empty
()
// Check if the Queue is empty.
public
bool
Empty
()
{
{
if
(
carQueue
.
Count
==
0
)
return
_carQueue
.
Count
==
0
;
{
return
true
;
}
return
false
;
}
}
public
Mutex
getMutex
()
// returns the Mutex.
public
Mutex
GetMutex
()
{
{
return
this
.
mutex
;
return
this
.
_
mutex
;
}
}
}
}
}
}
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