Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- struct node
- {
- int data;
- node *next;
- };
- void createList(node *&head, node*& tail, int item)
- {
- node* newNode = new node;
- newNode->next = NULL;
- newNode->data = item;
- if(head == NULL)
- {
- head = tail = newNode;
- }
- else
- {
- tail->next = newNode;
- tail = newNode;
- }
- }
- int deleteList(node *&head) //Start Function ( Delete all item in list )
- {
- node *temp;
- node *curr = new node;
- while(curr != NULL)
- {
- if(curr->data %2==1)
- {
- while(head != NULL)
- {
- temp = head;
- head = head->next;
- delete temp;
- break;
- }
- }
- curr = curr->next;
- cout<<"delete sec\n";
- }
- }
- int display(node *&head)
- {
- node *temp = head;
- node *prev = new node;
- node *curr = new node;
- curr = head;
- int temppos = 0,pos1 = 3,pos2 = 5;
- if(temp == NULL)
- {
- cout<<"Please Enter some data to increment it \n";
- return 0;
- }
- while(curr->next != NULL && temppos != pos1)
- {
- prev = curr;
- curr = curr->next;
- temppos++;
- }
- prev->data+=20;
- cout<<"3rd position is increment it : "<<prev->data<<endl;
- while(curr->next != NULL && temppos != pos2)
- {
- prev = curr;
- curr = curr->next;
- temppos++;
- }
- prev->data+=20;
- cout<<"5d position is increment it : "<<prev->data<<endl;
- while(temp != NULL)
- {
- cout<<"data is : "<<temp->data<<endl;
- temp = temp->next;
- }
- }
- int main()
- {
- node *tail,*head;
- head = tail = NULL;
- int choice,item;
- do
- {
- cout<<"1 - create list \n";
- cout<<"2 - inc by 20 the 3th and 5th\n";
- cout<<"4 - exit\n";
- cout<<"Enter your choice : ";cin>>choice;
- switch(choice)
- {
- case 1:
- for(int i=0;i<7;i++)
- {
- cout<<"Enter item : ";
- cin>>item;
- createList(head,tail,item);
- }
- break;
- case 2:
- display(head);
- break;
- default:
- cout<<"\n\n\n\t\t\tBYE BYE\n\n";
- }
- }
- while(choice != 4);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment