Example #1
0
void postFix()
{
    char ara[100];
    printf("please enter the Expression : ");
    scanf("%s",ara);
    int i = 0,newitem,k,result;
    while(ara[i] != '\0')
    {
        if(ara[i] >= '0' && ara[i] <= '9'){
            k = ara[i]-48;
            insertItem(k);
        }
        else {
            if(ara[i] == '+')newitem = list[length-2]+list[length-1];
            if(ara[i] == '-')newitem = list[length-2]-list[length-1];
            if(ara[i] == '*')newitem = list[length-2]*list[length-1];
            if(ara[i] == '/')newitem = list[length-2]/list[length-1];
            deleteLast();
            deleteLast();
            insertItem(newitem);
        }
        i++;

    }
    result = list[length-1];
    deleteLast;
    printf("%d\n",result);



}
int main(void)
{
    initializeList();
    while(1)
    {
        printf("1. Insert new item. 2. Delete item. 3. Search item. \n");
        printf("4. Insert Last. 5. Delete Last. 6. Print forward. \n");
        printf("7. Print backward. 8. exit.\n");

        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertFirst(item);
        }
        else if(ch==2)
        {
            int item = deleteLast();
            if(item!=NULL_VALUE) printf("Deleted: %d\n", item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct listNode * res = searchItem(item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int item;
            scanf("%d",&item);
            insertLast(item);
        }
        else if(ch==5)
        {
            deleteLast();
        }
        else if(ch==6)
        {
            printListForward();
        }
        else if(ch==7)
        {
            printListBackward();
        }
        else if(ch==8)
        {
            freeall(list);
            break;
        }
    }

}
Example #3
0
void deleteX(int x)
{
    node* tempNode = ALLOC_NODE();

    if(ourList->head->data == x)
        deleteFirst();
    if(ourList->tail->data == x)
        deleteLast();

    tempNode = ourList->head;
    int i;
    for(i=0; i < ourList->length; i++)
    {
        tempNode = tempNode->next;
        if(tempNode->data == x)
        {
            tempNode->prev->next = tempNode->next;
            tempNode->next->prev = tempNode->prev;
            node* auxNode = ALLOC_NODE();
            auxNode = tempNode;
            tempNode = tempNode->next;
            free(auxNode);
            tempNode = tempNode->prev;
        }
    }

}
Example #4
0
void deleteCurrent(ListRef L) {
    if (L == NULL) {
        printf( "Error: Called deleteCurrent() on NULL ListRef\n");
        //exit(EXIT_FAILURE);
    } else if (isEmpty(L)) {
        printf( "Error: Called deleteCurrent() on empty ListRef\n");
        //exit(EXIT_FAILURE);
    } else if (offEnd(L)) {
        printf( "Error: Called deleteCurrent() on ListRef without current \n");
        //exit(EXIT_FAILURE);
    }
    
    if (L->current == L->first) {
        deleteFirst(L);
    } else if(L->current == L->last) {
        deleteLast(L);
    } else {
        if (L->current->next != NULL) {
            L->current->next->prev = L->current->prev;
        }
        if (L->current->prev != NULL) {
            L->current->prev->next = L->current->next;
        }
        L->current->next = NULL;
        L->current->prev =NULL;
        freeNode(&(L->current));
        L->length--;
    }
    L->current = NULL;
}
Example #5
0
int main(){
	/*make list and output file*/
    ListHndl TheList = newList();
    FILE *out = fopen("out.out", "w");
    
    /*test empty in empty case*/
    if(isEmpty(TheList)) printf("Empty\n");
    else printf("not Empty\n");
    printf("testing insert one number\n");
    insertAtFront(TheList,(unsigned long*)25728);
    printf("%lu\n",(unsigned long)getFirst(TheList));
    printf("%lu\n",(unsigned long)getLast(TheList));
    /*should have same value*/
    
    printf("testing list with three numbers\n");
    insertAtFront(TheList,(unsigned long*)1589458);
    insertAtBack(TheList,(unsigned long*)35762111234);
    printf("%lu\n",(unsigned long)getFirst(TheList));
    
    /*test empty in full case*/
    if(isEmpty(TheList)) printf("Empty\n");
    else printf("not Empty\n");
    
	/*test moving the current pointer around*/
    moveFirst(TheList);
    moveNext(TheList);
    printf("%lu\n",(unsigned long)getCurrent(TheList));
    moveLast(TheList);
    movePrev(TheList);
    printf("%lu\n",(unsigned long)getCurrent(TheList));
    
	/*test printList*/
    printList(out, TheList);
    
	/*test makeEmpty*/
    makeEmpty(TheList);
    if(isEmpty(TheList)) printf("Empty\n");
    else printf("not Empty\n");
    
	/*test inserting functions*/
    insertAtFront(TheList,(unsigned long*)2);
    insertAtFront(TheList,(unsigned long*)1);
    insertAtFront(TheList,(unsigned long*)4);
    insertAtBack(TheList,(unsigned long*)4);
    moveLast(TheList);
    insertBeforeCurrent(TheList,(unsigned long*)3);
    printList(out,TheList);
    deleteFirst(TheList);
    deleteCurrent(TheList);
    deleteLast(TheList);
    printList(out,TheList);
    
    makeEmpty(TheList);
    printList(out,TheList);
    
	/*free list and close output file*/
    freeList(&TheList);
    fclose(out);
    return 0;
}
Example #6
0
void deleteX(int x)
{
    node* curr=(node*)malloc(sizeof(node));
    if(sent->head->data==x)
        deleteFirst();
    if(sent->tail->data==x)
        deleteLast();
    if(sent->tail==sent->head && sent->head->data==x)
    {

        free(sent->head);
        sent->tail=NULL;
        sent->head=NULL;
    }
    curr=sent->head;
    int i;
    for(i=0; i<sent->len; i++)
    {
        curr=curr->next;
        if(curr->data==x)
        {
            curr->prev->next = curr->next;
            curr->next->prev = curr->prev;
            node* aux = (node*)malloc(sizeof(node));
            aux= curr;
            curr = curr->next;
            free(aux);
            curr = curr->prev;
        }
    }

}
Example #7
0
void deleteElementX(int x)
{
    node *p=list->head;
    if (p->data==x) // If x is equal with the data in the first node we use the function deletefirst.
    {
        deleteFirst();
    }
    else
    {
        while  ((p!=NULL)&& (p!=list->tail))
        {
            p=p->next;
        }
        if (p->data==x)
        {
            if (p==list->tail)// if it coincide with the tail we use deleteLast.
                deleteLast();
            else
            {
                p->next->prev=p->prev;
                p->prev->next=p->next; // We reassemble the list.
                free(p);
                list->length--;
            }
        }
    }
}
void deleteAtPosition(node **head, int pos)
{
	int len = size(head);
	if (pos <= 0 || pos > (len))
	{
		printf("Position is not Valid\n");
		return;
	}
	if(pos == 1)
	{
		deleteFirst(head);
	}
	else if(pos == (len))
	{
		deleteLast(head);
	}
	else
	{
		// execution reach in this location if position is between 2 and len - 1
		node *curr = (*head)->next;
		node *prev = *head;
		int i = 2;	// start from 2nd node
		while(i != pos)
		{
			i ++;
			prev = curr;
			curr = curr->next;
		}
		prev->next = curr->next;	// curr points to old node at pos
		free(curr);
	}
	// size--;	
}
void ossimSingleImageChain::reset()
{
   bool result = true;
   do
   {
      result = deleteLast();
   } while (result);

   m_handler                = 0;
   m_bandSelector           = 0;
   m_histogramRemapper      = 0;
   m_brightnessContrast     = 0;
   m_sharpen                = 0;
   m_scalarRemapper         = 0;
   m_resamplerCache         = 0;
   m_resampler              = 0;
   m_geoPolyCutter          = 0;
   m_chainCache             = 0;

   m_addHistogramFlag       = false;
   m_addResamplerCacheFlag  = false;
   m_addChainCacheFlag      = false;
   m_remapToEightBitFlag    = false;
   m_threeBandFlag          = false;
   m_threeBandReverseFlag   = false;
   m_brightnessContrastFlag = false;
   m_sharpenFlag            = false;
   m_geoPolyCutterFlag      = false;
}
Example #10
0
int DList_deleteData(DList* list , int index){
    if(index >= list->length) return 0;
    if(index == 0) deleteFirst(list);
    else if(index == list->length-1)  deleteLast(list);
    else deleteMiddle( list , index);
    list->length--;
    return 1;
};
Example #11
0
int main()
{
    char s[100];
    scanf("%s",s);
    int i,b,a,c;
    for(i=0;s[i];i++)
    {
        if(s[i]=='+' || s[i]=='-' || s[i]=='*' || s[i]=='/')
        {
            b=list[length-1];
            deleteLast ();
            a=list[length-1];
            deleteLast ();

            switch (s[i])
            {
            case '+':
                c=a+b;
                break;
            case '-':
                c=a-b;
                break;
            case '*':
                c=a*b;
                break;
            case '/':
                c=a/b;
                break;
            }
            if(c<10)insertItem (c);
            else
            {
                insertItem (c/10);
                insertItem (c%10);
            }
        }
        else insertItem (s[i]-'0');
    }
    for(i=0;i<length;i++)printf("%d",list[i]);
    clearList ();
    printf("\n");
    return 0;

}
Example #12
0
int main()
{

    sent = (list*)malloc(sizeof(list));
    sent->head = NULL;
    sent->tail = NULL;
    sent->len = 0;


    FILE*  fin= fopen("input.txt", "r");

    char caz[20];
    int n;

    while(fscanf(fin, "%s", caz)>0)
    {
        if(strcmp(caz, "AF")==0)
        {
            fscanf(fin, "%d", &n);
            addFirst(n);
        }
        else if(strcmp(caz, "AL")==0)
        {
            fscanf(fin, "%d", &n);
            addLast(n);
        }
        else if(strcmp(caz, "DF")==0)
            deleteFirst();
        else if(strcmp(caz, "DL")==0)
            deleteLast();
        else if(strcmp(caz, "DOOM_THE_LIST")==0)
            doomTheList();
        else if(strcmp(caz, "DE")==0)
        {
            fscanf(fin, "%d", &n);
            deleteX(n);
        }
        if(strcmp(caz, "PRINT_ALL")==0)
            printList();
        else if(strcmp(caz, "PRINT_F")==0)
        {
            fscanf(fin, "%d", &n);
            printFirstX(n);
        }
        else if(strcmp(caz, "PRINT_L")==0)
        {
            fscanf(fin, "%d", &n);
            printLastX(n);
        }
    }

    fclose(fin);
    return 0;
}
// int size = 0;
int main()
{
	//Initialize Crcular linked list with NULL head
	node *head = NULL;
	int data = 10;
	// printf("Enter: ");
	// scanf("%d",&data);
	insertLast(&head, data);
	insertFirst(&head, 5);
	print(&head);
	printf("Size: %d\n", size(&head));

	printf("Insert at position 1\n");
	insertAtPosition(&head, 1,1);
	print(&head);
	printf("Size: %d\n", size(&head));

	printf("Insert at position 4\n");
	insertAtPosition(&head, 15,4);
	print(&head);
	printf("Size: %d\n", size(&head));

	deleteFirst(&head);
	print(&head);
	printf("Size: %d\n", size(&head));	

	deleteLast(&head);
	print(&head);
	printf("Size: %d\n", size(&head));	

	deleteAtPosition(&head,2);
	print(&head);
	printf("Size: %d\n", size(&head));	

	deleteAtPosition(&head,1);
	print(&head);
	printf("Size: %d\n", size(&head));	

	printf("New Circular linked list\n");
	node *head1 = NULL;
	createList(&head1);
	print(&head1);

	printf("Enter data want to search: ");
	scanf("%d", &data);
	search(&head1,data);

	printf("Sort a circular linked list\n");
	sort(&head1);
	print(&head1);

}
Example #14
0
//--------------------------------------------------------------
void testApp::keyPressed(int key){
    switch(key) {
		case 'd':
            deleteLast();
            break;
        case 'c':
            deleteAll();
            break;
        default:
            bArrowToPrev = !bArrowToPrev;
    }
    
}
Example #15
0
int main(int argc, char const *argv[])
{
	struct Node *list= create();
	append(&list,2);
	append(&list,3);
	add(&list,1,1);
	add(&list,4,2);
	
	
	deleteLast(&list);
	deleteLast(&list);
	deleteLast(&list);
	deleteLast(&list);
	add(&list,4,1);
	add(&list,22,5);
	add(&list,33,2);
	add(&list,11,3);
	add(&list,12,4);

	printList(list);

	return 0;
}
Example #16
0
/** \brief Remove the last item of a list
 *
 * \param[in,out] head Pointer to a list
 * \param[in] freeFunc Function pointer for freeing the memory of the list item
 *
 * Removes the last element of the given list and frees all associated memory.
 * If freeFunc is NULL, it tries to directly free the \a data item of each node.
 * This is useful if \a data is a pointer to a single element (e.g. string, int, ...)
 * For complex elements (e.g. structs) the user needs to provide a node-specific free() function.
 * (For example freeFeedItem() )
 */
void removeLast(NODE *head, listFuncPtr freeFunc) {
	NODE *lastNode = NULL;
	dbg_printf(P_DBG, "Removing last item...");
	lastNode = getLastNode(head);

	if(lastNode) {
		if(freeFunc) {
			freeFunc(lastNode->data);
		} else {
			am_free(lastNode->data);
		}
	}
	deleteLast(&head);
}
Example #17
0
void InputWidget::createActions() {

    //-- Rename input
    renameAction = new QAction(this);
    renameAction->setObjectName(QString::fromUtf8("rename"));
    renameAction->setEnabled(true);
    renameAction->setText(QApplication::translate("InputWidget", "Rename", 0,
                          QApplication::UnicodeUTF8));
    renameAction->connect(renameAction,SIGNAL(activated()),this,SLOT(rename()));

    //-- New input
    newinputAction = new QAction(this);
    newinputAction->setObjectName(QString::fromUtf8("newInput"));
    newinputAction->setEnabled(true);
    newinputAction->setText(QApplication::translate("InputWidget", "New Input", 0,
                            QApplication::UnicodeUTF8));
    newinputAction->connect(newinputAction,SIGNAL(activated()),this,SLOT(newInput()));

    //-- Delete last
    deleteinputAction = new QAction(this);
    deleteinputAction->setObjectName(QString::fromUtf8("deleteInput"));
    deleteinputAction->setEnabled(true);
    deleteinputAction->setText(QApplication::translate("InputWidget",
                               "Delete last Input", 0, QApplication::UnicodeUTF8));
    deleteinputAction->connect(deleteinputAction,SIGNAL(activated()),this,SLOT(deleteLast()));

    //-- Delete selected
    deleteselectedinputAction = new QAction(this);
    deleteselectedinputAction->setObjectName(QString::fromUtf8("deleteSelectedInput"));
    deleteselectedinputAction->setEnabled(true);
    deleteselectedinputAction->setText(QApplication::translate("InputWidget",
                                       "Delete selected Input", 0, QApplication::UnicodeUTF8));
    deleteselectedinputAction->connect(deleteselectedinputAction,SIGNAL(activated()),this,SLOT(deleteSelected()));

    //-- Input Up
    inputupAction = new QAction(this);
    inputupAction->setObjectName(QString::fromUtf8("moveupInput"));
    inputupAction->setEnabled(true);
    inputupAction->setText(QApplication::translate("InputWidget", "Move up", 0,
                           QApplication::UnicodeUTF8));
    inputupAction->connect(inputupAction,SIGNAL(activated()),this,SLOT(moveUp()));

    //-- Input Down
    inputdownAction = new QAction(this);
    inputdownAction->setObjectName(QString::fromUtf8("movedownInput"));
    inputdownAction->setEnabled(true);
    inputdownAction->setText(QApplication::translate("InputWidget", "Move down", 0,
                             QApplication::UnicodeUTF8));
    inputdownAction->connect(inputdownAction,SIGNAL(activated()),this,SLOT(moveDown()));
}
int main()
{
    initializeList();
    int i,j,k;
    int c;
    char sr[100];
    i=0;
    k=0;

    scanf("%s",&sr);

    while(sr[i]!='\0')
    {
        if(sr[i]=='(' || sr[i]=='{' || sr[i]=='[')
        {
            insertItem(sr[i]);
        }
        else
        {
            if(length==0)
            {
                k=1;
                break;
            }
            c=list[length-1];
            deleteLast();
            if(sr[i]==')' && c!='(')
            {
                k=1;
                break;
            }
            else if(sr[i]=='}' && c!='{')
            {
                k=1;
                break;
            }
            else if(sr[i]==']' && c!='[')
            {
                k=1;
                break;
            }
        }
        i++;
    }
    j=getlength();
    if(!j && !k)printf("Balanced");
    else printf("Not Balanced");
    clear();
}
Example #19
0
// deletes the elements in the current node
void deleteCurrent(ListRef L) {
    if(L->first==L->last)
        makeEmpty(L);
    if(!isEmpty(L)) {
        if(L->current==L->last)
            deleteLast(L);
        else if(L->current==L->first)
            deleteFirst(L);
        else {
            L->current->next->prev=L->current->prev;
            L->current->prev->next=L->current->next;
        }

    }
}
Example #20
0
int List::deleteAt(int pos) {
	if (pos <= 0)
		return deleteFirst();
	else if (pos >= getSize())
		return deleteLast();
	else {
		ListItem *del = first;
		while (pos-- > 0) {
			del = del->getNext();
		}
		int val = del->getContent();
		delete del;
		currentSize--;
		return val;
	}
}
int main() {
  printf("start of program: "); heapReport();
  
  FILE *inputFile = openInputFile("input.txt");
  FILE *outputFile = openOutputFile("output.txt");

  LinkedList list;

  // Read 10 integers from the input file, adding them
  // alternately to the beginning and end of the list.
  // After each change to the list, write the contents of the
  // list to the output file.

  fprintf(outputFile, "CREATING LIST:\n");
  int count;
  for (count = 1; count <= 5; count++) {
    list = readAndAddToStart(list, inputFile);
    printList(list, outputFile);
    list = readAndAddToEnd(list, inputFile);
    printList(list, outputFile);
  } // end for

  // Show heap space used on standard input
  printf("after creating list: "); heapReport();

  fprintf(outputFile, "\nWHILE DELETING FROM LIST:\n");
  int start = 1; // 1 (true) means addint to start
  while (list != NULL) {
    if (start) 
      list = deleteFirst(list);
    else
      list = deleteLast(list);
    start = !start;
    printList(list, outputFile);
  } // end for

  // Show heap space again; if delete functions have freed space
  // it should be zero.
  printf("after emptying list: "); heapReport();

  fclose(inputFile);
  fclose(outputFile);
  printf("after closing files: "); heapReport();


  return 0;
} // end main
Example #22
0
void deleteElementByKey(int x)
{
    //the previous node to the one that has to be deleted will be memorized
    NODE *prevNode=NULL;
    int found=0;
    if (head!=NULL)
    {
        NODE *currentNode,*aux;
        currentNode=head;
        //the list is traversed up to the node which has to be deleted
        while ((!found)&&(currentNode!=NULL))
        {
            //the case in which the node to be deleted is a head or a tail are taken into consideration
            if (currentNode->data==x)
            {
                if (currentNode==head)
                    {
                        deleteFirst();
                        found=1;
                    }
                else
                {
                    if (currentNode==tail)
                        {
                        deleteLast();
                        found=1;
                        }
                    else
                    {
                        aux=currentNode;
                        prevNode->next=currentNode->next;
                        currentNode=prevNode->next;
                        free(aux);
                        found=1;
                    }
                }
            }
            else
            {
                //the previous node is linked to the element following the one due to be deleted
                prevNode=currentNode;
                currentNode=currentNode->next;
            }
        }

    }
}
Example #23
0
void deleteCurrent(ListRef L){     //deletes current node and frees it
   if(!isEmpty(L) && !offEnd(L)){  //pre: !isEmpty() and !offEnd()
      if(atLast(L))
         deleteLast(L);
      else if(atFirst(L))
         deleteFirst(L);
      else{
         NodeRef oldnode = L->current;
         L->current->prev->next = L->current->next;
         L->current->next->prev = L->current->prev;
         L->current = L->current->next;
         free(oldnode);
         oldnode = NULL;
         L->length--;
      }
   }
}
Example #24
0
void main(int argc, char * argv[])
{	
	int i, test, vyska;
	float vaha, vek;
	char * jmeno;
	FILE *jm_soub;
	tClovek searchTest={0,0,0,"Matej Kocour"}, nacti[5];
	tUkDbClovek db=NULL, tmpUk;

	if (argc >=2)
	{
		if( (jm_soub = fopen(argv[1], "r")) == NULL) {
			fprintf(stderr, "Soubor %s se nepodarilo otevrit.\n", argv[1]);
			printf("Soubor %s se nepodarilo otevrit.\n", argv[1]);
			exit(1);
		}
			else {
				jm_soub = fopen(argv[1], "r");
				for(i=0; i<5; i++) {				
					fscanf(jm_soub, "%i %.1f %.1f %s\n", &nacti[i].vyska, &nacti[i].vaha, &nacti[i].vek, &nacti[i].jmeno);				
				}			
				fclose(jm_soub);
				printf("\nNacteni informaci ze souboru dokonceno");
			}
		
		db=insertFirst(db, nacti[0]);
		db=insertFirst(db, nacti[1]);
		db=insertLast(db, nacti[2]);
		db=insert(db, nacti[3]);
		db=insert(db, nacti[4]);
		printf("\nInformace ulozeny do seznamu");
		tmpUk=search(db, nacti[2]);
		if (tmpUk!=NULL && tmpUk->clovek.jmeno!=NULL) printf("Found: %s\n", tmpUk->clovek.jmeno);
		tmpUk=search(db, searchTest);
		if (tmpUk!=NULL && tmpUk->clovek.jmeno!=NULL) printf("Found: %s\n", tmpUk->clovek.jmeno);
		db=deleteLast(db);
		db=deleteAny(db);
		while ((db=deleteFirst(db))!=NULL); /* smazani celeho seznamu */
		printf("\nSeznam je smazan");
	}
	else printf("parametr \"jmeno souboru\" nebyl zadan!\n");
}
Example #25
0
 void delete_X(int x)
    {
        NodeT* aux;
        aux = head;
        while((aux!=NULL)&&(aux->code!=x))
        {
            aux=aux->next;
        }
        if (aux==head) deleteFirst();
        else if (aux==tail) deleteLast();
        else
        {
            aux->prev->next=aux->next;
            aux->next->prev=aux->prev;
            free (aux);
        }
santinela.head=head;
    santinela.length--;
    santinela.tail=tail;
    }
int List::deleteAt(int pos) {
	if (pos <= 0) {
		return deleteFirst();
	}
	else if (pos >= currentSize - 1) {
		return deleteLast();
	}
	else {
		int index = pos;
		ListItem* p = first;
		// iterate over elements
		while (index-- > 0) {
			p = p->getNext();
		}
		int content = p->getContent();
		delete p;
		--currentSize;
		return content;
	}
}
int main() {
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for (i = 0; i < n; i++) {
    scanf("%s%d", com, &key);
    if (com[0] == 'i') {insert(key); np++; size++;}
    else if (com[0] == 'd') {
      if (strlen(com) > 6) {
        if (com[6] == 'F') deleteFirst();
        else if (com[6] == 'L') deleteLast();
      } else {
        deleteKey(key); nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}
Example #28
0
void main(){
    float z; 
    do{
        printf("Geben Sie eine weitere Zahl ein!");
        scanf("%f", &z);
        if(z != 0){
            paste( z); 
        }
        printAll();
         
    } while (z != 0);
    printf("test"); 
    //unsigned int usecs;
    //usecs = 1000*1000;
    while (list_head != NULL){
        printf("Lösch was \n");
        fflush(stdout);
        deleteLast();    
        
      //  usleep(usecs);
        
    }
    printf("det wars\n");
}
Example #29
0
int main()
    {
        int x;
        FILE *f_in=fopen("input.dat","r");
        if (f_in == NULL)
        {
            perror("cannot open the file!");
        }

        FILE *f_out=fopen("output.dat","a");
        char option[15];

        while (fscanf(f_in,"%s",option)>0)
        {

            if (strcmp(option,"AF")==0)
            {
                fscanf(f_in,"%d",&x);
                addFirst(x);
            }

            if (strcmp(option,"AL")==0)
            {
                fscanf(f_in,"%d",&x);
                addLast(x);
            }

            if (strcmp(option,"DF")==0)
            {
                deleteFirst();
            }

            if (strcmp(option,"DL")==0)
            {
                deleteLast();
            }

            if (strcmp(option,"DOOM_THE_LIST")==0)
            {
                doom();
            }

            if (strcmp(option,"DE")==0)
            {
                fscanf(f_in,"%d",&x);
                delete_X(x);
            }

            if (strcmp(option,"PRINT_ALL")==0)
            {
                printall();
            }

            if (strcmp(option,"PRINT_F")==0)
            {
                fscanf(f_in,"%d",&x);
                print_first_X(x);
            }

           if (strcmp(option,"PRINT_L")==0)
            {
                fscanf(f_in,"%d",&x);
                print_last_X(x,f_out);
            }


        }

        fclose(f_in);
        fclose(f_out);


        return 0;
    }
int main(void)
{
    initializeList();
    while(1)
    {
        printf("1. Insert new item. 2. Delete item. 3. Search item. \n");
        printf("4. Insert new item at last of list. 5. Insert new item after old item in list.\n");
        printf("6. Delete first item in list 7. Delete last item in list.\n");
        printf("8. Print. 9. exit.\n");



        int ch;
        scanf("%d",&ch);
        if(ch==1)
        {
            int item;
            scanf("%d", &item);
            insertItem(item);
        }
        else if(ch==2)
        {
            int item;
            scanf("%d", &item);
            deleteItem(item);
        }
        else if(ch==3)
        {
            int item;
            scanf("%d", &item);
            struct listNode * res = searchItem(item);
            if(res!=0) printf("Found.\n");
            else printf("Not found.\n");
        }
        else if(ch==4)
        {
            int item;
            scanf("%d",&item);
            insertLast(item);
        }
        else if(ch==5)
        {
            int oldItem,newItem;
            printf("Old item: ");
            scanf("%d",&oldItem);
            printf("New item: ");
            scanf("%d",&newItem);
            insertAfter(oldItem,newItem);
        }
        else if(ch==6)
        {
            deleteFirst();
        }
        else if(ch==7)
        {
            deleteLast();
        }
        else if(ch==8)
        {
            printList();
        }
        else if(ch==9)
        {
            break;
        }
    }

}