void llist::addbeforeIth(int I, el_t New) { // case(exception) // --------------- if(I < 1 || I > Count + 1) throw OutOfRange(); // case(I is the front) // -------------------- else if(I == 1) addFront(New); // case(I is the rear) // ------------------- else if(I == Count + 1) addRear(New); // case(I will be squished between two nodes) // ------------------------------------------ else { Node *temp_P = Front; Node *temp_N; for(int j = 1; j < I - 1; j++) temp_P = temp_P->Next; temp_N = temp_P->Next; temp_P->Next = new Node; temp_P = temp_P->Next; temp_P->Elem = New; temp_P->Next = temp_N; Count++; } }
int main() { system("color 0a"); int ch,data; do { printf("Enter choice : \n1. Add at rear\n2.Add at front\n3.Remove from rear\n4.Remove from Front\n5.Display\n6.search for an item\n0. to exit\n"); scanf("%d",&ch); switch(ch) { case 1:printf("Enter data :"); scanf("%d",&data); addRear(data); break; case 2: printf("Enter data :"); scanf("%d",&data); addFront(data); break; case 3:removeRear(); break; case 4:removeFront(); break; case 5:display(); break; case 6: printf("Enter data to search :"); scanf("%d",&data); search(data); break; } }while(ch!=0); return 0; }
int main() { int ch,data; do { printf("1.Add at rear\n2.Add at front\n3.Remove from rear\n4.remove from front\n5.Display\n0.exit\n"); scanf("%d",&ch); switch(ch) { case 1:printf("Enter data : "); scanf("%d",&data); addRear(data); break; case 2:printf("Enter data : "); scanf("%d",&data); addFront(data); break; case 3:removeRear(); break; case 4:removeFront(); break; case 5:display(); break; case 0:printf("\nExitting\n"); break; } }while(ch!=0); return 0; }
void LinkListDoubleTemplate< TYPE >::initialize( unsigned long size ) { TYPE *object; if( front != 0 ) { deallocate(); } for( unsigned long i; i < size; i++ ) { object = new TYPE; addRear( object ); } }
void addFront(int data) { node *tmp; node *ptr=(node *)malloc(sizeof(node)); ptr->data=data; ptr->next=ptr; if(top==NULL)addRear(data); else { ptr->next=top; top=ptr; tmp=top; if(top->next->next==top->next)top->next->next=top; else { tmp=tmp->next; while(tmp->next!=top->next ) tmp=tmp->next; tmp->next=top; } } }
void ServerClientList::addClient( ServerClientListData *client_data ) { addRear( client_data ); }