-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathl6_i.cpp
44 lines (41 loc) · 851 Bytes
/
l6_i.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <iostream>
using namespace std;
struct Node{
int data;
Node *next;
Node(int x){
data=x;
next=nullptr;
}
};
Node *insert(Node *head,int x){
Node* t=new Node(x);
t->next=head;
return t;
}
Node *deletefirst(Node *head) {
if (head == nullptr) {
return nullptr; // List is empty, nothing to delete
}
Node *temp = head;
head = head->next; // Update the head to the next node
delete temp; // Delete the old head node
return head; // Return the new head
}
Node *display(Node *head) {
Node* t = head;
while (t != nullptr) {
cout << t->data << " -> ";
t = t->next;
}
cout << "null" << endl;
}
int main(){
Node* head=nullptr;
int x;
for(int i=0;i<5;i++){
cin>>x;
head=insert(head,x);
}
display(head);
}