Last active
September 27, 2015 07:24
-
-
Save Zerk123/fd0181a0a2550e64811f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include<iostream> | |
| using namespace std; | |
| struct node{ | |
| int data; | |
| node *next; | |
| }; | |
| node *tail; | |
| node *head; | |
| void Insert(int x){ | |
| node *current; | |
| current = new node; | |
| if (head == NULL){ | |
| current->data = x; | |
| current->next = head; | |
| head = current; | |
| tail = current; | |
| } | |
| else{ | |
| current->data = x; | |
| current->next = head; | |
| tail->next = current; | |
| head = current; | |
| } | |
| } | |
| void Delete(int x){ | |
| node *temp = head; | |
| node *tail = head; | |
| node *temp1=head; | |
| int count = 0; | |
| if (x == temp->data){ | |
| while (tail->next != head){ | |
| tail = tail->next; | |
| } | |
| temp = temp->next; | |
| head = temp->next; | |
| tail->next = tail->next->next; | |
| return; | |
| } | |
| while (temp->data != x){ | |
| count = count++; | |
| temp = temp->next; | |
| } | |
| for (int i = 0; i < count - 1; i++){ | |
| temp1 = temp1->next; | |
| } | |
| temp1->next = temp1->next->next; | |
| } | |
| void Search(int y){ | |
| node *temp = head; | |
| if (temp->data == y){ | |
| cout << "Found!!!" << endl; | |
| } | |
| else{ | |
| while (temp->data != y){ | |
| temp = temp->next; | |
| } | |
| if (temp->next == head && temp->data != y){ | |
| cout << "Not Found!!!" << endl; | |
| exit(0); | |
| } | |
| } | |
| } | |
| void Print(){ | |
| node *temp = head; | |
| cout << "LINK LIST->" << endl; | |
| do{ | |
| cout << temp->data << endl; | |
| temp = temp->next; | |
| } while (temp!= head); | |
| } | |
| int main(){ | |
| Insert(1); | |
| Insert(2); | |
| Insert(3); | |
| Insert(4); | |
| Insert(5); | |
| Print(); | |
| Search(2); | |
| Delete(1); | |
| Print(); | |
| Search(1); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment