/////////
// Sequentially store linear tables
////////
package main
import "fmt"
const MAXSIZE = 20 //Define the array length
//Define the linear table structure
type List struct {
Element [MAXSIZE]int //Arrays that store linear table elements
length int //Length of linear table
}
//Initialize the linear table, d: initialized element, l position
func (l *List) InitList(d int, p int) {
[p] = d
++
}
//Insert element
//d: Inserted data
//p: Insert position
func (l *List) Insert(d int, p int) bool {
if p < 0 || p >= MAXSIZE || >= MAXSIZE {
return false
}
if p < {
for k := - 1; k >= p; k-- {
[k+1] = [k]
}
[p] = d
++
return true
} else {
[] = d
++
return true
}
}
//Delete the element
//p: Delete the location of the element
func (l *List) Delete(p int) bool {
if p < 0 || p > || p >= MAXSIZE {
return false
}
for ; p < -1; p++ {
[p] = [p+1]
}
[-1] = 0
--
return true
}
func main() {
var l List
i := 0
b := 1
//Initialize a linear table
for i < 15 {
(b, i)
i++
b++
}
//Insert an element
(1, 13)
//Delete an element
(5)
(l)
}
// Sequentially store linear tables
////////
package main
import "fmt"
const MAXSIZE = 20 //Define the array length
//Define the linear table structure
type List struct {
Element [MAXSIZE]int //Arrays that store linear table elements
length int //Length of linear table
}
//Initialize the linear table, d: initialized element, l position
func (l *List) InitList(d int, p int) {
[p] = d
++
}
//Insert element
//d: Inserted data
//p: Insert position
func (l *List) Insert(d int, p int) bool {
if p < 0 || p >= MAXSIZE || >= MAXSIZE {
return false
}
if p < {
for k := - 1; k >= p; k-- {
[k+1] = [k]
}
[p] = d
++
return true
} else {
[] = d
++
return true
}
}
//Delete the element
//p: Delete the location of the element
func (l *List) Delete(p int) bool {
if p < 0 || p > || p >= MAXSIZE {
return false
}
for ; p < -1; p++ {
[p] = [p+1]
}
[-1] = 0
--
return true
}
func main() {
var l List
i := 0
b := 1
//Initialize a linear table
for i < 15 {
(b, i)
i++
b++
}
//Insert an element
(1, 13)
//Delete an element
(5)
(l)
}