- Joined
- Jan 30, 2013
- Messages
- 12,758
Okay, pretty much I'm new to this LL stuff (all I know well is arrays, not pointers). So, pretty much I need the LL to traverse through a list of data I made according to their key in a specific order.
Here's a code I made. I know it's broken but at least show how far I already get.
Aim :
Input :
Order of Key :
1-3-2-5-4
Output :
100
30
50
25
40
Here's a code I made. I know it's broken but at least show how far I already get.
Code:
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node* link;
} node;
struct node* A;
void nodes()
{
struct node* temp = (struct node*)malloc(sizeof(node));
(*temp).data = 2;
(*temp).link = NULL;
A = temp;
}
int main()
{
struct node* temp1 = A;
while (temp1->link != NULL)
{
temp1 = temp->link;
printf("%d\n",temp1->data);
}
temp1->link = temp;
return 0;
}
Aim :
Input :
Data | Key |
100 | 1 |
50 | 2 |
30 | 3 |
40 | 4 |
25 | 5 |
Order of Key :
1-3-2-5-4
Output :
100
30
50
25
40