Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import "stdio.h";
- import "stdlib.h";
- type SList struct {
- value int;
- next *SList;
- };
- func SListNode(value int) *SList
- {
- var n *SList = stdlib.malloc(sizeof(type SList));
- n.value = value;
- n.next = nil;
- return n;
- }
- func SListPush(head **SList, value int)
- {
- if *head == nil {
- *head = SListNode(value);
- return;
- }
- n := SListNode(value);
- n.next = *head;
- *head = n;
- }
- func SListPop(head **SList) (value int)
- {
- if *head != nil {
- cur := *head;
- value = cur.value;
- *head = cur.next;
- stdlib.free(cur);
- }
- }
- func main(argc int, argv **byte) int
- {
- var list *SList;
- for i := 0; i < 5; i++ {
- SListPush(&list, i*10);
- }
- for i := 0; i < 5; i++ {
- v := SListPop(&list);
- stdio.printf("%d\n", v);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment