datastructure -3
datastructure -3
Representation of a Polynomial,
Polynomial Addition;
pointers
The logical ordering is represented by having
class Node {
public:
int data;
Node* next;
};
CREATE A SIMPLE LINKED LIST WITH 3 NODES.
#include <iostream>
using namespace std;
class Node {
public:
int data;
Node* next;
};
#include<iostream>
using namespace std;
class Node {
public:
int data;
Node* next;
};
//This function prints contents of linked list starting from the
given node
void printList(Node* n)
{
while (n != NULL) {
cout << n->data << " ";
n = n->next;
}
}
// Driver code
int main()
{
Node* head = NULL;
Node* second = NULL;
Node* third = NULL;
printList(head);
return 0;
}
Output: 1 2 3
INSERTING A NEW NODE IN A LINKED LIST
position
INSERTING AT THE START
Inserting a new node at the start of the list
means that the new node will serve as the new
head.
It also fills the data within the node. Moreover, it
possible one
The storage allocation for each term in the
Input :
p1= 13x8 + 7x5 + 32x2 + 54
p2= 3x12 + 17x5 + 3x3 + 98
step 2& 3.
Step 2: if the value of p1 node exponent is greater
Disadvantages
Uses two pointers, which results in more
Traversing
Forward_traverse:
Backward _traverse:
Insertion
The new node is inserted at the beginning.
The new node is inserted at the end.
The new node is inserted after a given node.
The new node is inserted before a given node.
Deletion
The first node is deleted.
The last node is deleted.
The node after a given node is deleted.
The node before a given node is deletedon
TRAVERSAL