0% found this document useful (0 votes)
4 views2 pages

Linked List Structure

Uploaded by

f20220732
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views2 pages

Linked List Structure

Uploaded by

f20220732
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Linked List Structure

struct Node
{
int data;
Node *next;
Node(int x)
{
data = x;
next = NULL;
}
};
void listTraversal(Node *head)
{
Node *curr = head;
while(curr!=NULL)
{
cout << curr->data << " ";
curr = curr->next;
}
}

Node *insertAtPosition(Node *head, int pos, int x)


{
Node *curr = head;
int curr_pos = 1;
while(curr_pos!=pos-1)
{
curr = curr->next;
curr_pos++;
}
Node *temp = new Node(x);
temp->next = curr->next;
curr->next = temp;
return head;

}
Node *deleteFirstNode(Node *head)
{
head = head->next;
return head;
}

Node *deleteTail(Node *head)


{
Node *curr = head;
while(curr->next->next!=NULL)
{
curr = curr->next;
}
curr->next = NULL;
return head;

int findPosition(Node *head, int x)


{
Node *curr = head;
int pos = 1;
while((curr!=NULL)&&(curr->data)!=x)
{
curr = curr->next;
pos++;
}
if(curr!=NULL)
{
return pos;
}
else
return -1;
}

You might also like