





Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Data Structure and Algorithm Lab Task 03
Typology: Assignments
1 / 9
This page cannot be seen from the preview
Don't miss anything!






Lab Task(s): Perform the following using C++ Programming Language
first = new node(); second = new node(); third = new node(); fourth = new node(); fifth = new node();
first->data=4; first->next= second;
second->data=6; second->next= third;
third->data=9; third->next=fourth;
fourth->data = 7; fourth->next = fifth;
fifth->data = 6; fifth->next = NULL;
display(first); }
class Node { public: int data; Node * next; };
void print_list(Node * n) { while (n != NULL) { cout << n->data << " "; n = n->next; } }
int linklistsize(Node head){ int size = 0; Node current = head; while (current != NULL) { size++; current = current->next; } return size; }
int main() { system ("color f0"); Node * head = NULL; Node * second = NULL; Node * third = NULL; Node * fourth = NULL; Node * tail = NULL;
head = new Node(); second = new Node(); third = new Node(); fourth = new Node(); tail = new Node();
#include
c++; } else { cin>>num; node * temp1 = new node; temp1->data=num; temp->next=temp1; temp=temp1; } } int a; cout<<"For displaying Element of linklist Press 1: ";cin>>a; if(a==1) printlinkedlist(head); }
while(head!=NULL) { cout<<head->data<<" "; head=head->next; } cout<<endl; } int main() { system("color f0"); Node *head = NULL; push(&head,61); push(&head,32); push(&head,60); push(&head,59); push(&head,61); push(&head,30); push(&head,54); push(&head,19); cout<<"Given Linked List: "; printList(head); cout<<"\nDeleting node "<< head->next->next->data<<" "; deleteNode(head, head->next->next); cout<<"\nModified Linked List: "; printList(head);
cout<<"\nDeleting first node "; deleteNode(head, head);
cout<<"\nModified Linked List: "; printList(head); return 0; }