- Added setReverse to reverse the order of a set
[fw/sdcc] / src / SDCCset.c
index 1746a5a9023aa38ce567523129cb624ffbdebaec..61b68a05931d5364ba28ee3ae7131897fd0edd46 100644 (file)
@@ -404,6 +404,26 @@ elementsInSet (set * s)
   return count;
 }
 
+/*-----------------------------------------------------------------*/
+/* reverseSet - reverse the order of the items of a set            */
+/*-----------------------------------------------------------------*/
+
+set *
+reverseSet(set * s)
+{
+  set *t = NULL;
+  set *u = NULL;
+
+  while(s->next) {
+    t = s->next;
+    s->next = u;
+    u = s;
+    s = t;
+  }
+  s->next = u;
+  return s;
+}
+
 /*-----------------------------------------------------------------*/
 /* subtractFromSet - take away from set1 elements of set2          */
 /*-----------------------------------------------------------------*/