Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Ele struct {
|
||||
Data interface{}
|
||||
Next *Ele
|
||||
}
|
||||
|
||||
func (e *Ele) insert(data interface{}) {
|
||||
if e == nil {
|
||||
panic("attept to modify nil")
|
||||
}
|
||||
e.Next = &Ele{data, e.Next}
|
||||
}
|
||||
|
||||
func (e *Ele) printList() {
|
||||
if e == nil {
|
||||
fmt.Println(nil)
|
||||
return
|
||||
}
|
||||
fmt.Printf("(%v", e.Data)
|
||||
for {
|
||||
e = e.Next
|
||||
if e == nil {
|
||||
fmt.Println(")")
|
||||
return
|
||||
}
|
||||
fmt.Print(" ", e.Data)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
h := &Ele{"A", &Ele{"B", nil}}
|
||||
h.printList()
|
||||
h.insert("C")
|
||||
h.printList()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue