-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinkedlist.cpp
48 lines (43 loc) · 1.08 KB
/
linkedlist.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
45
46
47
48
#include<iostream>
#include<cstdio>
using namespace std;
typedef struct node{
int data;
node *link;
};
void insert_at_start(node *start, int data){
node *temp = new node;
temp->data = data;
temp->link = start->link;
start->link = temp;
}
void print_list(node *start){
node *temp = start;
if(start==NULL)
printf("Linked list is empty\n");
else
printf("The data present in the list are : ");
while(start!=NULL){
printf("%d ",temp->data);
temp = temp->link;
}
}
int main(){
node *start = new node;
int choice,x;
while(1){
printf("Enter the valid choice \n");
printf("\n1. Insert data at the begining");
printf("\n2. Print the data of the list");
scanf("%d",&choice);
if(choice==1){
printf("\nEnter the data that you want to add");
scanf("%d",&x);
insert_at_start(start,x);
}
else if(choice==2){
print_list(start);
}
}
return 0;
}