|
|
1.1 ! root 1: /* ! 2: * queues.c 1.4 ! 3: * ! 4: * Queue Handling Functions for Spreadsheet Program `vis' ! 5: * ! 6: * A. F. Gettier ! 7: * Bell Laboratories ! 8: * Update made 11/1/82 11:13:33 ! 9: * Retrieved 11/15/82 13:22:42 ! 10: */ ! 11: #include "vis.h" ! 12: #include <stdio.h> ! 13: ! 14: /*LINTLIBRARY*/ ! 15: /* ! 16: * Add to the end of a queue ! 17: */ ! 18: void qadd( hdr, val ) ! 19: struct qheader *hdr; ! 20: struct node *val; ! 21: { ! 22: struct qentry *t, *a, *b; ! 23: struct node *x; ! 24: t = NODE( qentry ); ! 25: t->next = 0; ! 26: t->nodeptr = val; ! 27: a = hdr->first; ! 28: b = 0; ! 29: if ( a == 0 ) { ! 30: hdr->first = hdr->last = t; ! 31: return; ! 32: } ! 33: loop { ! 34: x = a->nodeptr; ! 35: /* ! 36: * don't enter if present ! 37: */ ! 38: if ( (val->row == x->row && val->col < x->col ) ! 39: || val->row < x->row ) { ! 40: b = a; ! 41: a = a->next; ! 42: if ( a == 0 ) { ! 43: b->next = hdr->last = t; ! 44: return; ! 45: } ! 46: } ! 47: else { ! 48: if (val->row == x->row && val->col == x->col ) ! 49: return; ! 50: if ( b == 0 ) { ! 51: t->next = hdr->first; ! 52: hdr->first = t; ! 53: } ! 54: else { ! 55: t->next = b->next; ! 56: b->next = t; ! 57: } ! 58: return; ! 59: } ! 60: } ! 61: } ! 62: ! 63: ! 64: ! 65: /* ! 66: * Read from the front of a queue ! 67: */ ! 68: struct node *qread( hdr ) ! 69: struct qheader *hdr; ! 70: { ! 71: struct node *t; ! 72: struct qentry *s; ! 73: if ( hdr->first == 0 ) return( 0 ); ! 74: t = (hdr->first)->nodeptr; ! 75: s = (hdr->first)->next; ! 76: free( (char *)hdr->first ); ! 77: hdr->first = s; ! 78: if ( s == 0 ) hdr->last = 0; ! 79: return( t ); ! 80: } ! 81: ! 82: ! 83: ! 84: /* ! 85: * Empty a queue ! 86: */ ! 87: void qempty( hdr ) ! 88: struct qheader *hdr; ! 89: { ! 90: struct qentry *t; ! 91: while ( hdr->first != 0 ) { ! 92: t = hdr->first; ! 93: free( (char *)hdr->first ); ! 94: hdr->first = t; ! 95: } ! 96: hdr->last = 0; ! 97: } ! 98: ! 99: ! 100: ! 101: /* ! 102: * Initialize a queue ! 103: */ ! 104: void qinit( hdr ) ! 105: struct qheader *hdr; ! 106: { ! 107: hdr->first = 0; ! 108: hdr->last = 0; ! 109: } ! 110: ! 111: ! 112: ! 113: /* ! 114: * Copy a Queue ! 115: */ ! 116: struct qheader *qcopy( hdr ) ! 117: struct qheader *hdr; ! 118: { ! 119: struct qheader *t; ! 120: struct qentry *s, *s1; ! 121: t = NODE( qheader ); ! 122: t->first = 0; ! 123: t->last = 0; ! 124: s1 = hdr->first; ! 125: while( s1 != 0 ) { ! 126: s = NODE( qentry ); ! 127: if ( t->first == 0 ) ! 128: t->first = s; ! 129: else ! 130: (t->last)->next = s; ! 131: t->last = s; ! 132: s->next = 0; ! 133: s->nodeptr = s1->nodeptr; ! 134: s1 = s1->next; ! 135: } ! 136: return( t ); ! 137: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.