0
Link list
you have to insert n elements in link list and the value of n is entered by user. how to create such link list.incase of array we can declare a big array ,but in case of link list we have to write that much lines.please anyone help me to solve it.
18 Answers
+ 9
Please show us your attempt.
+ 10
SL is SoloLearn.
No, I just solve problems from different sites like CodeSignal. Just trying to become better at solving problems.
We should stop this conversation here since chatting in the Q&A is not allowed.
+ 9
I will try to answer your problems as well as I can. 🙂 As I'm not comfortable with sharing my facebook profile, why not join the SoloLearn Discord server? You can get more (and maybe better) answers to your questions:
https://www.sololearn.com/Discuss/689391/?ref=app
+ 9
I'm not actually. I prefer C++, but I like playing around with stuff from the SL lessons.
+ 8
You can do:
struct node {
int data;
node *next;
}
int main(){
node *head, *ptr;
head = new node;
ptr = head;
for (int i = 1; i <= n; i++){
cin >> ptr->data;
ptr = ptr->next;
}
ptr->next = NULL;
ptr = NULL;
return 0;
}
And you should use int main() instead of void main() as it isn't C nor C++, as said in this link:
http://www.stroustrup.com/bs_faq2.html#void-main
+ 8
I did declare new node. You don't need to write struct in declaration.
We have a member variable data. On each run of the loop, the user enters a new one and it links to the next node. So if n is 5, we scan 5 elements. After the loop, we link the last node to NULL.
+ 8
Sorry, but I don't know C. My code generates the list at runtime.
+ 8
Your welcome 🍪
+ 8
Codecademy had some good courses about web development. Try searching on SL about web development resources, you can find some useful links.
+ 1
Anime FanGirl thank you for replying.😊
but still I have some questions..
1-why didn't you declare new node.
I didn't get if the value of n is 5 then ...? because we can only scan 2 elements
+ 1
ok thank. you. i m joining h.hope it will be helpful.thank you once again 😊😊
0
Anime FanGirl I have no idea how to start . would you please help me? this is what I know...
struct node{
int data;
struct node *ptr;
};
struct node *p1,*p2,*p3,*head,*temp;
void main()
{
p1=(struct node *) malloc(sizeof(struct node));
p2=(struct node *) malloc(sizeof(struct node));
p3=(struct node *) malloc(sizeof(struct node));
head=p1;
p1->ptr=p2;
p2->ptr=p3;
p3->ptr=NULL;
}
/*I have created a link list of 3 elements but what if user will enter more than 3 elements .DO WE have to write that much lines of code*/
0
sorry for again disturbing but can you write your code in c. i know that a[100] we can store 100 elements on this array but in linked list we cannot declare its eyes like array so we don't know.
I didn't get the concept where you are using loop by loop how can we create a linked list automatically.
0
we should have enough link list to store n elements and we don't know the value of n.
0
ok thank you for your effort.😊😊
keep replying of my problems please..can I contact you in fb?
0
Anime FanGirl can you tell me how to learn web development. like making. website. Every where in online palteform like YouTube they just teach basic(Data types,loop,function,class etc) they don't teach how to make apps,websites .can you suggest me some channels or anything from where I can learn advance in these language so than I can make websites,apps.
0
ok thank you.
BTW you seem like a gud web developer
0
what is SL?
oh c++ you do competitive programming? preparation for icpc?