//İnsertion at beginning of linklist.
struct Node
{
int data;
struct Node* next;
};
struct Node* head;
void insert (int x)
{
Node* temp = (Node*)malloc(sizeof(struct Node));
temp -> data = x;
temp -> next = head;
head = temp;
}
void print()
{
struct Node* temp = head;
printf("List is: ");
while(temp != NULL)
{
printf("%d ", temp -> data);
temp = temp -> next;
}
printf("\n");
}
int main() {
head = NULL;
printf("How many numbers? \n:");
int n, i, x;
scanf("%d",n);
for(i = 0; i < n; i++)
{
printf("Enter the number \n");
scanf("%d", x);
insert(x);
print();
}
return 0;
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter