You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type List struct { // list btbd2 b 2 node head and tail
Head *NodeL // pointer to head awl node w7da fl linked list
Tail *NodeL // pointer to tail de l node eli hfdl ndef feha
}
func ListPushBack(l *List, data interface{}) { // no3 interface by2ra ay no3 data
newnode := &NodeL{Data: data} // newnode de l data eli hdefha ll list, Data dh l goz2 eli f struct node, data de esmaha hna fl function w dymn l next bt3ha nil
if l.Head == nil { //awl wa7da fadya // lw eli gya nil
l.Head = newnode // 5leha btsawy l data
l.Tail = newnode // defli l data hna
return // dh w ana b7ot ISA awl node
}
if l.Tail.Next == nil {
l.Tail.Next = newnode
}
//l.Tail.Next = newnode
l.Tail = newnode
//l.Tail = newnode
// 5li l next bta3 l tail pointer ll new node (e3ml l data fl tail w 5li l text nil)
}
func main() {
link := &List{}
ListPushBack(link, "Hello")
ListPushBack(link, "man")
ListPushBack(link, "how are you")
for link.Head != nil {
fmt.Println(link.Head.Data)
link.Head = link.Head.Next
}
}
//Write a function ListPushBack that inserts a new element NodeL
// at the end of the list l while using the structure List.