# TAWK program to manipulate doubly linked lists. # This code is exerpted from the TAWK manual. # This TAWK program requires TAWK 5.0 or higher # Add an existing item to doubly linked list. function dllink(list,item) { item["flink"] = list["flink"] item["blink"] = list list["flink"]["blink"] = item list["flink"] = item } # create a new item, and add to the doubly linked list. function dladd(list) { local item = table() # Alocate a new table dllink(list,item) return item } # Delete item from doubly linked list. function dlunlink(item) { item["flink"]["blink"] = item["blink"] item["blink"]["flink"] = item["flink"] } # Allocate and return a new sentinel for a doubly linked list. function dlinit() { local head = table() # Allocate a new table head["flink"] = head["blink"] = head return head } # Print the contents of all the items in a doubly linked list. # Do not print the "flink" and "blink" fields. function dlprint(list) { local i,item,cnt=1 print "=====" for (item = list["flink"]; item != list; item = item["flink"]) { print "ITEM NUMBER",cnt++ for (i in item) { if (i != "flink" && i != "blink") print "\t",i,"=",item[i] } } } # Here is some code to exercise the routines above: #BEGIN { # local head # head = dlinit() # head["label"] = "sentinel" # dllink(head,table("label","first item")) # dlprint(head) # dllink(head["blink"],table("label","second item")) # dlprint(head) # dlunlink(head["blink"]) # dlprint(head) #}