// Prints out all the links, starting at the current link going // backwards void printAll(ring *r) { setFirst(r); for (int i = getLength(r); i>0; i--) { printf("%d: %s\n", i, getCurrent(r)); shiftForward(r); } }
void LSQ_ShiftPosition(LSQ_IteratorT iterator, LSQ_IntegerIndexT shift){ if(NULL == iterator || !shift) return; TreeIteratorPtr it = iterator; if(it->state == IT_PAST_REAR && shift > 0 || it->state == IT_BEFORE_FIRST && shift < 0) return; if(it->state == IT_BEFORE_FIRST){ LSQ_SetPosition(it, 0); shift--; } else if(it->state == IT_PAST_REAR){ LSQ_SetPosition(it, it->tree->size - 1); shift++; } if(shift > 0) shiftForward(it, shift); else shiftBackward(it, -shift); }
// Queries the use to find out what actions they want to perform. // Runs continuously until the user selects 'Quit'. Contains basic // operations for manipulating a doubly linked list, except adding // a new node. int query(ring *r) { printf("What would you like to do?\n"); printf("1 - View previous website\n"); printf("2 - View next website\n"); printf("3 - View latest website\n"); printf("4 - View first website\n"); printf("5 - Open current website\n"); printf("6 - Remove from history\n"); printf("7 - Print number of links stored\n"); printf("8 - Print all links (from last to first)\n"); printf("9 - Quit\n"); char option, nl; char link[120] = "open "; scanf("%c%c", &option, &nl); switch(option) { case '1': shiftForward(r); printf("Previous:\n%s\n", getCurrent(r)); return 1; break; case '2': shiftBackward(r); printf("Next:\n%s\n", getCurrent(r)); return 1; break; case '3': setFirst(r); printf("Latest:\n%s\n", getCurrent(r)); return 1; break; case '4': setLast(r); printf("First:\n%s\n", getCurrent(r)); return 1; break; case '5': printf("Opening:\n%s\n", getCurrent(r)); strcat(link, getCurrent(r)); system(link); return 1; break; case '6': deleteCurrent(r); printf("Previous:\n%s\n", getCurrent(r)); return 1; break; case '7': printf("There are %d links stored.\n", getLength(r)); printf("Current: \n%s\n", getCurrent(r)); return 1; break; case '8': printAll(r); printf("\nCurrent: \n%s\n", getCurrent(r)); return 1; break; case '9': return 0; break; default: printf("Please enter a valid option!\n"); return 1; } }