
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Golang Program to define a singly linked list.
Examples
Approach to solve this problem
Step 1 − Let’s define a structure of the node.
Step 2 − Make the Linked List such that the previous node would store the address of the next node.
Example
package main import "fmt" type Node struct { value int next *Node } func NewNode(value int) *Node{ var n Node n.value = value n.next = nil return &n } func TraverseLinkedList(head *Node){ fmt.Printf("Linked List: ") temp := head for temp != nil { fmt.Printf("%d ", temp.value) temp = temp.next } } func main(){ head := NewNode(30) head.next = NewNode(10) head.next.next = NewNode(40) head.next.next.next = NewNode(40) TraverseLinkedList(head) }
Output
Linked List: 30 10 40 40
- Related Questions & Answers
- C++ Program to Implement Singly Linked List
- C++ Program to Implement Circular Singly Linked List
- C++ Program to Implement Sorted Singly Linked List
- Golang Program to reverse a given linked list.
- Python Program to Convert a given Singly Linked List to a Circular List
- C++ Program to Implement Sorted Circularly Singly Linked List
- Python Program to Check whether a Singly Linked List is a Palindrome
- Convert singly linked list into circular linked list in C++
- Convert singly linked list into XOR linked list in C++
- Golang program to define a binary tree
- Program to convert binary search tree to a singly linked list in C++?
- Difference between Singly linked list and Doubly linked list in Java
- C Program to reverse each node value in Singly Linked List
- Golang Program to delete the first node from a linked list.
- Golang Program to delete the last node from a linked list.
Advertisements