int main() { struct Queue *q = CreateQueue(); InsertFront(q,1); InsertFront(q,3); InsertRear(q,0); InsertRear(q,5); printf("%d\n",DeleteFront(q)->element); printf("%d\n",DeleteRear(q)->element); }
void InsertPosition(node *first, node *last, int pos) { node prev = NULL, cur = *first, temp; int i; if (pos <= 0 || pos > count + 1) { printf("\nYou entered an invalid position."); return; } temp = Create(); if (pos == 1) InsertFront(first, last, &temp); else if (pos == count + 1) InsertRear(first, last, &temp); else { for (i = 1; i < pos; ++i) { prev = cur; cur = cur->rlink; } temp->rlink = cur; temp->llink = prev; prev->rlink = temp; cur->llink = temp; } ++count; }
int main(void) { Menu menu; List list; InitList(&list); do { Data x; switch (menu = SelectMenu()) { case InsFront: x = Read("先頭に挿入", NO | NAME); InsertFront(&list, x); break; case InsRear: x = Read("末尾に挿入", NO | NAME); InsertRear(&list, x); break; case RmvFront: RemoveFront(&list); break; case RmvRear: RemoveRear(&list); break; case PrintCrnt: PrintCrntNode(&list); break; case RmvCrnt: RemoveCrnt(&list); break; case SrchNo: x = Read("探索", NO); if (SearchNode(&list, x, NoEqual) != NULL){ PrintCrntNode(&list); } break; case SrchName: x = Read("探索", NAME); if(SearchNode(&list, x, NameEqual) != NULL){ PrintCrntNode(&list); } break; case PrintAll: PrintList(&list); break; case Clear: ClearList(&list); break; } } while (menu != Term); TermList(&list); return (0); }
void main() { node first = NULL, last = NULL; int i, ch; while (1) { printf("\nCIRCULAR LINKED LIST"); printf("\n1. INSERT\n2. DELETE\n3. DISPLAY\n4. EXIT"); printf("\nEnter your choice: "); scanf("%d", &i); //system("cls"); //clrscr(); switch (i) { case 1: printf("\n1. Insert at front"); printf("\n2. Insert at rear"); printf("\nEnter your choice: "); scanf("%d", &ch); switch (ch) { case 1: InsertFront(&first, &last); break; case 2: InsertRear(&first, &last); break; default: printf("\n You chose an invalid option."); } break; case 2: printf("\n1. Delete from front"); printf("\n2. Delete from rear"); printf("\nEnter your choice: "); scanf("%d", &ch); switch (ch) { case 1: DeleteFront(&first, &last); break; case 2: DeleteRear(&first, &last); break; default: printf("\n You chose an invalid option."); } break; case 3: Display(&first, &last); break; case 4: return; default: printf("\nInvalid choice. Try again."); } } }