[test] added new test

master
Furkan Türkal 5 years ago
parent d16fb68aae
commit 3610263f99
No known key found for this signature in database
GPG Key ID: 3015FE56155820F2

@ -60,11 +60,11 @@ func Push(head_ref **Node, new_data int) {
/* MoveNode() function takes the node from the front of the
   source, and move it to the front of the dest.
   It is an error to call this with the source list empty.
 
   Before calling MoveNode():
   source == {1, 2, 3}
   dest == {1, 2, 3}
 
   Affter calling MoveNode():
   source == {2, 3}
   dest == {1, 1, 2, 3} */
@ -83,8 +83,8 @@ func MoveNode(dest_ref **Node, source_ref **Node) {
}
/* Takes two lists sorted in increasing order, and splices
   their nodes together to make one big sorted list which
   is returned.  */
   their nodes together to make one big sorted list which
   is returned.  */
func SortedMerge(a *Node, b *Node) *Node {
//A dummy first node to hang the result on
dummy := New()
@ -96,18 +96,18 @@ func SortedMerge(a *Node, b *Node) *Node {
dummy.next = nil
for {
if (a == nil){
if a == nil {
//If either list runs out, use the other list
tail.next = b
break
} else if (b == nil){
} else if b == nil {
tail.next = a
break
}
if (a.data <= b.data){
if a.data <= b.data {
MoveNode(&(tail.next), &a)
} else{
} else {
MoveNode(&(tail.next), &b)
}
@ -118,11 +118,21 @@ func SortedMerge(a *Node, b *Node) *Node {
}
//This function prints contents of linked list starting from the given node
func printList(n *Node){
func printList(n *Node) {
for n != nil {
fmt.Print(n.data)
fmt.Print(" ,")
n = n.next
}
}
func GetDataList(n *Node) []int {
data := []int{}
for n != nil {
fmt.Println(n.data)
data = append(data, n.data)
n = n.next
}
return data
}
func main() {

Loading…
Cancel
Save