bool LinkedList::insert(Node_entry el){ Node *newNode, *aux;//, *currentNode;//, *nextNode; if (front==NULL){ insertFront(el); return true; } if(el<front->entry){ insertFront(el); return true; } if(el>rear->entry){ insertRear(el); return true; } newNode = new Node(el); if(newNode == NULL) return false; aux = front; while(el>=aux->entry){ aux = aux->next; } newNode->next = aux; newNode->prev = aux->prev; aux->prev=newNode; return true; }
void askStr() { int str; printf("Integer:\n"); scanf("%d",&str); insertRear(str); displayArray(); }
void insertRear(Node * now,int endflag){ int data; scanf("%d",&data); if(data==endflag){ now->link=NULL; } else{ Node * rear = (Node*)malloc(sizeof(Node)); rear->data=data; now->link=rear; insertRear(now->link,endflag); } }
void askUser() { int num; int x=10; int i; char choices; struct node *current; current=head; system("cls"); printf("\n[1]-ENQUEUE\n[2]-DEQUEUE\n[3]-FRONT\n[4]-REAR\n"); choices=getch(); switch(choices) { case '1': num=askNum(); for(i=0;i<num;i++) { while(x<0||x>9) { printf("Enter number: "); scanf("%d",&x); } insertRear(x); x=10; displayArray(); } getch(); askUser(); break; case '2': deleteFront(); displayArray(); getch(); askUser(); break; case '3': if(head!=NULL) { printf("%d",head->data); } else { printf("List is empty"); } getch(); askUser(); break; case '4': while(current->next!=NULL) { current=current->next; } printf("%d",current->data); getch(); askUser(); break; default: getch(); break; } }
void askUser() { int num; int x=10; int i; char choices; system("cls"); printf("\n[1]-DISPLAY ARRAY\n[2]-INSERT REAR\n[3]-INSERT FRONT\n[4]-INSERT INTO\n[5]-DELETE FRONT\n[6]-DELETE REAR\n[7]-DELETE ITEM\n[8]-DELETE ALL ITEM\n[9]-MAKE UNIQUE\n"); choices=getch(); switch(choices) { case '1': displayArray(); getch(); askUser(); break; case '2': num=askNum(); for(i=0;i<num;i++) { while(x<0||x>9) { printf("Enter number: "); scanf("%d",&x); } insertRear(x); x=10; displayArray(); } getch(); askUser(); break; case '3': num=askNum(); for(i=0;i<num;i++) { while(x<0||x>9) { printf("Enter number: "); scanf("%d",&x); } insertFront(x); x=10; displayArray(); } getch(); askUser(); break; case '4': displayArray(); insertInto(); displayArray(); getch(); askUser(); break; case '5': deleteFront(); displayArray(); getch(); askUser(); break; case '6': deleteRear(); displayArray(); getch(); askUser(); break; case '7': displayArray(); deleteItem(); displayArray(); getch(); askUser(); break; case '8': displayArray(); deleteAllItem(); displayArray(); getch(); askUser(); break; case '9': displayArray(); makeUnique(); displayArray(); getch(); askUser(); break; default: getch(); break; } }