forked from TECHOUS/DSKaKhel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInsert_at_Head.cpp
More file actions
52 lines (41 loc) · 790 Bytes
/
Insert_at_Head.cpp
File metadata and controls
52 lines (41 loc) · 790 Bytes
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
45
46
47
48
49
50
51
#include<iostream>
using namespace std;
struct node
{
int data;
struct node *next;
};
node *head = NULL;
void INSERT_HEAD(int value)
{
node *newNode;
newNode = new node;
newNode->data = value;
if(head == NULL)
{ newNode->next = NULL;
head = newNode;
}
else{
newNode->next = head;
head = newNode;
}
cout<<"DATA INSERTED AT HEAD SUCCESSFULLY"<<endl;
}
int main()
{int choice,element;
cout<<"ENTER THE CHOICE\n1.INSERT AT HEAD"<<endl;
cin>>choice;
while(choice != -1)
{
switch(choice)
{
case 1:
cout<<"ENTER THE ELEMENT"<<endl;
cin>>element;
INSERT_HEAD(element);
break;
}
cout<<"ENTER THE CHOICE\n1.INSERT AT HEAD"<<endl;
cin>>choice;
}
}