-
Notifications
You must be signed in to change notification settings - Fork 0
List and unique list #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Palezehvat
wants to merge
9
commits into
master
Choose a base branch
from
ListAndUniqueList
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
aadcec5
+лист, +др. лист. Тесты для листа и др. листа
palorel b1fcc5a
Merge branch 'master' into ListAndUniqueList
palorel bc3da02
Merge branch 'master' into ListAndUniqueList
palorel de69f23
Merge branch 'master' into ListAndUniqueList
palorel 5d23bb5
Добыл csproj
palorel 752a69f
+main для CI
palorel 4369c93
+Unsigns
palorel c34a0be
Ревью
palorel 3037d42
Ревью
palorel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| | ||
| Microsoft Visual Studio Solution File, Format Version 12.00 | ||
| # Visual Studio Version 17 | ||
| VisualStudioVersion = 17.4.33403.182 | ||
| MinimumVisualStudioVersion = 10.0.40219.1 | ||
| Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ListAndUniqueList", "ListAndUniqueList\ListAndUniqueList.csproj", "{7F7F9968-FB78-4353-AC51-E0D43F4A7557}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsList", "TestsList\TestsList.csproj", "{BB4EEB6F-6C72-4F81-A0BD-4AADA4AD9058}" | ||
| EndProject | ||
| Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestsUniqueList", "TestsUniqueList\TestsUniqueList.csproj", "{6FA174A8-43FA-48FB-B3B7-E747E92E4A66}" | ||
| EndProject | ||
| Global | ||
| GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
| Debug|Any CPU = Debug|Any CPU | ||
| Release|Any CPU = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
| {7F7F9968-FB78-4353-AC51-E0D43F4A7557}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {7F7F9968-FB78-4353-AC51-E0D43F4A7557}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {7F7F9968-FB78-4353-AC51-E0D43F4A7557}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {7F7F9968-FB78-4353-AC51-E0D43F4A7557}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {BB4EEB6F-6C72-4F81-A0BD-4AADA4AD9058}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {BB4EEB6F-6C72-4F81-A0BD-4AADA4AD9058}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {BB4EEB6F-6C72-4F81-A0BD-4AADA4AD9058}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {BB4EEB6F-6C72-4F81-A0BD-4AADA4AD9058}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| {6FA174A8-43FA-48FB-B3B7-E747E92E4A66}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
| {6FA174A8-43FA-48FB-B3B7-E747E92E4A66}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
| {6FA174A8-43FA-48FB-B3B7-E747E92E4A66}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
| {6FA174A8-43FA-48FB-B3B7-E747E92E4A66}.Release|Any CPU.Build.0 = Release|Any CPU | ||
| EndGlobalSection | ||
| GlobalSection(SolutionProperties) = preSolution | ||
| HideSolutionNode = FALSE | ||
| EndGlobalSection | ||
| GlobalSection(ExtensibilityGlobals) = postSolution | ||
| SolutionGuid = {B598B7F0-1489-463C-B6BB-24CBDBDD7F83} | ||
| EndGlobalSection | ||
| EndGlobal |
This file contains hidden or 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,6 @@ | ||
| namespace ListAndUniqueList; | ||
|
|
||
| /// <summary> | ||
| /// Throw exception when item is already in unique list | ||
| /// </summary> | ||
| public class InvalidItemException : Exception {} | ||
6 changes: 6 additions & 0 deletions
6
ListAndUniqueList/ListAndUniqueList/InvalidPositionException.cs
This file contains hidden or 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,6 @@ | ||
| namespace ListAndUniqueList; | ||
|
|
||
| /// <summary> | ||
| /// Throw exception when the position is incorrect | ||
| /// </summary> | ||
| public class InvalidPositionException : Exception {} |
This file contains hidden or 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,227 @@ | ||
| namespace ListAndUniqueList; | ||
|
|
||
| /// <summary> | ||
| /// A list for storing and interacting with int type elements | ||
| /// </summary> | ||
| public class List | ||
| { | ||
| private ListElement? Head; | ||
| private ListElement? Tail; | ||
|
|
||
| /// <summary> | ||
| /// Adding an item to the list | ||
| /// </summary> | ||
| virtual public void AddElement(int position, int value) | ||
| { | ||
| if (Head == null) | ||
| { | ||
| var item = new ListElement(value); | ||
| Head = item; | ||
| Tail = item; | ||
| ++Head.SizeList; | ||
| } | ||
| else | ||
| { | ||
| ++Head.SizeList; | ||
| ListElement item = new ListElement(value); | ||
| if (Tail == null) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| if (position == 0) | ||
| { | ||
| var temp = Head.Next; | ||
| Head = item; | ||
| Head.Next = temp; | ||
| return; | ||
| } | ||
| if (position == Head.SizeList - 1) | ||
| { | ||
| Tail.Next = item; | ||
| Tail = item; | ||
| return; | ||
| } | ||
| var walker = Head; | ||
| int counter = 0; | ||
|
|
||
| while (walker != null && walker.Next != null && counter != position) | ||
| { | ||
| walker = walker.Next; | ||
| counter++; | ||
| } | ||
| if (walker == null || walker.Next == null) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| else | ||
| { | ||
| var temp = walker.Next.Next; | ||
| walker.Next = item; | ||
| item.Next = temp; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Deletes an item at the end of the list | ||
| /// </summary> | ||
| /// <exception cref="NullPointerException">Throws an exception when the list is empty</exception> | ||
| /// <returns>Element which was deleted</returns> | ||
| virtual public int RemoveElement(int position) | ||
| { | ||
| if (Head == null || Tail == null) | ||
| { | ||
| throw new NullListException(); | ||
| } | ||
| if (position > Head.SizeList) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| if (Tail == Head) | ||
| { | ||
| var itemFromTail = Tail.Value; | ||
| Tail = null; | ||
| Head = null; | ||
| return itemFromTail; | ||
| } | ||
| if (position == 0) | ||
| { | ||
| var itemFromHead = Head.Value; | ||
| Head = Head.Next; | ||
| return itemFromHead; | ||
| } | ||
| if (position == Head.SizeList) | ||
| { | ||
| var itemFromTail = Tail.Value; | ||
| var walkerForTail = Head; | ||
| while (walkerForTail != null && walkerForTail.Next != Tail) | ||
| { | ||
| walkerForTail = walkerForTail.Next; | ||
| } | ||
| if (walkerForTail == null) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| Tail = walkerForTail; | ||
| walkerForTail.Next = null; | ||
| } | ||
|
|
||
| int counter = 0; | ||
| var walker = Head; | ||
| while (walker != null && walker.Next != null && walker.Next.Next != null && counter != position - 1) | ||
| { | ||
| walker = walker.Next; | ||
| counter++; | ||
| } | ||
| if (walker == null || walker.Next == null) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| var item = walker.Next.Value; | ||
| walker.Next = walker.Next.Next; | ||
| --Head.SizeList; | ||
| return item; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Prints list items | ||
| /// </summary> | ||
| virtual public void PrintTheElements() | ||
| { | ||
| ListElement? walker = Head; | ||
| int counter = 0; | ||
| while (walker != null) | ||
| { | ||
| Console.Write(counter); | ||
| Console.Write(' '); | ||
| Console.WriteLine(walker.Value); | ||
| walker = walker.Next; | ||
| ++counter; | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Changes values by position | ||
| /// </summary> | ||
| /// <exception cref="NullPointerException">Throws an exception when the list is empty</exception> | ||
| virtual public void ChangeValueByPosition(int position, int newValue) | ||
| { | ||
| if (Head == null || Tail == null) | ||
| { | ||
| throw new NullListException(); | ||
| } | ||
| ListElement? walker = Head; | ||
| int counter = 0; | ||
| while (walker != null && counter != position) | ||
| { | ||
| walker = walker.Next; | ||
| counter++; | ||
| } | ||
| if (walker == null) | ||
| { | ||
| throw new NullReferenceException(); | ||
| } | ||
| walker.Value = newValue; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks if the list is empty | ||
| /// </summary> | ||
| virtual public bool IsEmpty() => Head == null; | ||
|
|
||
| /// <summary> | ||
| /// Returns the value by position | ||
| /// </summary> | ||
| /// <exception cref="NullPointerException">Throws an exception when the list is empty</exception> | ||
| /// <exception cref="InvalidPositionException">Throws an excwption when there is no such position in the list</exception> | ||
| virtual public int ReturnValueByPosition(int position) | ||
| { | ||
| if (Head == null || Tail == null) | ||
| { | ||
| throw new NullListException(); | ||
| } | ||
| var walker = Head; | ||
| int counter = 0; | ||
| while (walker != null && counter != position) | ||
| { | ||
| walker = walker.Next; | ||
| ++counter; | ||
| } | ||
| if (walker == null) | ||
| { | ||
| throw new InvalidPositionException(); | ||
| } | ||
| return walker.Value; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Checks if there is an item in the list | ||
| /// </summary> | ||
| /// <returns>Returns true if present and false if absent</returns> | ||
| public bool Contains(int value) | ||
| { | ||
| var walker = Head; | ||
| while (walker != null) | ||
| { | ||
| if (walker.Value == value) | ||
| { | ||
| return true; | ||
| } | ||
| walker = walker.Next; | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| public class ListElement | ||
| { | ||
| public ListElement(int value) | ||
| { | ||
| Value = value; | ||
| } | ||
| public int Value { get; set; } | ||
|
|
||
| public ListElement? Next { get; set; } | ||
|
|
||
| public int SizeList { get; set; } | ||
| } | ||
| } |
10 changes: 10 additions & 0 deletions
10
ListAndUniqueList/ListAndUniqueList/ListAndUniqueList.csproj
This file contains hidden or 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,10 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>net7.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| </PropertyGroup> | ||
|
|
||
| </Project> |
This file contains hidden or 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,6 @@ | ||
| namespace ListAndUniqueList; | ||
|
|
||
| /// <summary> | ||
| /// Throw exception when list is empty | ||
| /// </summary> | ||
| public class NullListException : Exception {} |
This file contains hidden or 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,31 @@ | ||
| namespace ListAndUniqueList; | ||
|
|
||
| /// <summary> | ||
| /// List only without repetitions | ||
| /// </summary> | ||
| public class UniqueList : List | ||
| { | ||
| public override void AddElement(int position, int value) | ||
| { | ||
| if (!Contains(value)) | ||
| { | ||
| base.AddElement(position, value); | ||
| } | ||
| else | ||
| { | ||
| throw new InvalidItemException(); | ||
| } | ||
| } | ||
|
|
||
| public override void ChangeValueByPosition(int position, int newValue) | ||
| { | ||
| if (!Contains(newValue) || ReturnValueByPosition(position) == newValue) | ||
| { | ||
| base.ChangeValueByPosition(position, newValue); | ||
| } | ||
| else | ||
| { | ||
| throw new InvalidItemException(); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Надо комментарии и к исключениям тоже