generated from OtusGolang/home_work
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge new version home_work fnd my version
- Loading branch information
DimVlas
authored and
DimVlas
committed
Oct 5, 2024
1 parent
9c57809
commit 2221038
Showing
22 changed files
with
99 additions
and
166 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module github.com/DimVlas/otus_hw/hw01_hello_otus | ||
|
||
go 1.19 | ||
go 1.22 | ||
|
||
require golang.org/x/example v0.0.0-20230731131755-00c7068f9d83 |
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/DimVlas/otus_hw/hw02_unpack_string | ||
|
||
go 1.19 | ||
go 1.22 | ||
|
||
require github.com/stretchr/testify v1.7.0 | ||
|
||
|
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,131 +1,26 @@ | ||
package hw04lrucache | ||
|
||
type List interface { | ||
Len() int // Кол-во элементов в списке. | ||
Front() *ListItem // Первый элемент списка. | ||
Back() *ListItem // Последний элемент списка. | ||
PushFront(v interface{}) *ListItem // Добавление элемента в начало списка. | ||
PushBack(v interface{}) *ListItem // Добавление элемента в конец списка. | ||
Remove(i *ListItem) // Удаление элемента из списка. | ||
MoveToFront(i *ListItem) // Переместить элемент вперед. | ||
Len() int | ||
Front() *ListItem | ||
Back() *ListItem | ||
PushFront(v interface{}) *ListItem | ||
PushBack(v interface{}) *ListItem | ||
Remove(i *ListItem) | ||
MoveToFront(i *ListItem) | ||
} | ||
|
||
type ListItem struct { | ||
Value interface{} | ||
Prev *ListItem | ||
Next *ListItem | ||
Prev *ListItem | ||
} | ||
|
||
type list struct { | ||
len int | ||
front *ListItem | ||
back *ListItem | ||
List // Remove me after realization. | ||
// Place your code here. | ||
} | ||
|
||
// Создать новый двусвязный список. | ||
func NewList() List { | ||
return new(list) | ||
} | ||
|
||
// Кол-во элементов в списке. | ||
func (lst *list) Len() int { | ||
return lst.len | ||
} | ||
|
||
// Первый элемент списка. | ||
func (lst *list) Front() *ListItem { | ||
return lst.front | ||
} | ||
|
||
// Последний элемент списка. | ||
func (lst *list) Back() *ListItem { | ||
return lst.back | ||
} | ||
|
||
// Добавление элемента в начало списка. | ||
func (lst *list) PushFront(v interface{}) *ListItem { | ||
itm := &ListItem{ | ||
Value: v, | ||
Next: lst.front, | ||
} | ||
lst.front = itm | ||
lst.len++ | ||
|
||
if itm.Next == nil { | ||
lst.back = itm | ||
return itm | ||
} | ||
|
||
itm.Next.Prev = itm | ||
return itm | ||
} | ||
|
||
// Добавление элемента в конец списка. | ||
func (lst *list) PushBack(v interface{}) *ListItem { | ||
itm := &ListItem{ | ||
Value: v, | ||
Prev: lst.back, | ||
} | ||
lst.back = itm | ||
lst.len++ | ||
|
||
if itm.Prev == nil { | ||
lst.front = itm | ||
return itm | ||
} | ||
|
||
itm.Prev.Next = itm | ||
return itm | ||
} | ||
|
||
// Удаление элемента из списка. | ||
func (lst *list) Remove(i *ListItem) { | ||
if i == nil { | ||
return | ||
} | ||
|
||
if i.Prev == nil && i.Next == nil { // единственный элемент | ||
lst.front = nil | ||
lst.back = nil | ||
lst.len-- | ||
return | ||
} | ||
|
||
if i.Prev == nil { // первый элемент | ||
i.Next.Prev = nil | ||
lst.front = i.Next | ||
lst.len-- | ||
return | ||
} | ||
|
||
if i.Next == nil { // последний элемент | ||
i.Prev.Next = nil | ||
lst.back = i.Prev | ||
lst.len-- | ||
return | ||
} | ||
|
||
i.Prev.Next = i.Next | ||
i.Next.Prev = i.Prev | ||
lst.len-- | ||
} | ||
|
||
// Переместить элемент вперед. | ||
func (lst *list) MoveToFront(i *ListItem) { | ||
if i.Prev == nil { // первый элемент | ||
return | ||
} | ||
|
||
if i.Next != nil { // элемент из середины | ||
i.Prev.Next = i.Next // предыдущий ссылается на следующий | ||
i.Next.Prev = i.Prev // следующий ссылается на предыдущий | ||
} else { // последний элемент | ||
i.Prev.Next = nil | ||
lst.back = i.Prev | ||
} | ||
|
||
i.Prev = nil | ||
i.Next = lst.front | ||
lst.front = i | ||
i.Next.Prev = i | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
module github.com/DimVlas/otus_hw/hw07_file_copying | ||
|
||
go 1.19 | ||
go 1.22 | ||
|
||
require github.com/stretchr/testify v1.9.0 | ||
|
||
|
Oops, something went wrong.