Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- struct TList
- {
- int value;
- TList* next;
- };
- bool isEmpty(TList* lst)
- {
- return lst==NULL;
- }
- int addElem(TList** lst, int newValue)
- {
- TList * temp = new TList;
- temp->value = newValue;
- temp->next = NULL;
- if(isEmpty((*lst)))
- *lst = temp;
- else
- {
- TList* temp1 = *lst;
- while(temp1->next!=NULL)
- temp1 = temp1->next;
- temp1->next = temp;
- }
- return 0;
- }
- int printList(TList* lst)
- {
- while(lst!=NULL)
- {
- cout<<lst->value<<" ";
- lst = lst->next;
- }
- return 0;
- }
- int delElem(TList** lst, int delValue)
- {
- if(*lst!=NULL)
- {
- TList* temp = *lst;
- while((*lst!=NULL)&&((*lst)->value==delValue))
- {
- temp = (*lst)->next;
- delete *lst;
- (*lst) = temp;
- }
- if(*lst!=NULL)
- {
- temp = *lst;
- TList* temp1 = *lst;
- while(temp!=NULL)
- {
- while((temp!=NULL) && (temp->value!=delValue))
- {
- temp1 = temp;
- temp = temp->next;
- }
- if((temp!=NULL)&&(temp->value==delValue))
- {
- temp1->next = temp->next;
- delete temp;
- temp = temp1;
- }
- if(temp!=NULL)
- temp = temp->next;
- }
- }
- return 0;
- }
- return -1;
- }
- int main()
- {
- TList* List = NULL;
- int t;
- ifstream inputFile("input.txt");
- if(inputFile)
- {
- while(!inputFile.eof())
- {
- inputFile>>t;
- addElem(&List,t);
- }
- printList(List);
- delElem(&List,2);
- cout<<endl;
- printList(List);
- return 0;
- }
- else
- return -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement