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; } }
// Loads ring with nodes containing a fake web-history. Demonstrates // both types of insert, and a backward shift. Ordered so that the most // recently visited webpage is 'first' in the linked list (but was // entered last in this). void loadRing(ring *r) { insertAfter(r, "http://www.google.com"); insertBefore(r, "https://www.google.co.uk/?gfe_rd=cr&ei=58RkVqCSEITP0wWvzrPQDg#q=what%20is%20computer%20science"); shiftBackward(r); insertBefore(r, "http://www.bbc.co.uk/guides/zxgdwmn"); shiftBackward(r); insertBefore(r, "https://www.google.co.uk/?gfe_rd=cr&ei=58RkVqCSEITP0wWvzrPQDg#q=what%20is%20computer%20science"); shiftBackward(r); insertBefore(r, "https://www.google.co.uk/?gfe_rd=cr&ei=58RkVqCSEITP0wWvzrPQDg#q=university+of+bristol+computer+science"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/Teaching/"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/Teaching/yearpage.jsp?stage=1"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/Teaching/"); shiftBackward(r); insertBefore(r, "https://www.google.co.uk/?gfe_rd=cr&ei=58RkVqCSEITP0wWvzrPQDg#q=university+of+bristol+computer+science"); shiftBackward(r); insertBefore(r, "http://www.cs.bris.ac.uk/"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/ugadmissions/"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/ugadmissions/whyBristol/"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/ugadmissions/howToApply/"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/People/"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/People/staff.jsp"); shiftBackward(r); insertBefore(r, "https://www.cs.bris.ac.uk/People/personal.jsp?key=4196"); shiftBackward(r); insertBefore(r, "http://www.cs.bris.ac.uk/~ian/"); shiftBackward(r); insertBefore(r, "http://pastebin.com/SusF2063"); setFirst(r); }