joel
in fact, problem we discussed, is more for C lang
thry both have pointers 🤷‍♂️
Oleksandr
thry both have pointers 🤷‍♂️
but Cpp-style allocation (via new[]) gives us error)
Oleksandr
in fact, that is not even an allocation... just dummy guard while compilation
joel
thry?
typo
Vladimir
constexpr
C++ magic
joel
still trying to figure out what is going on
joel
:D
what distro do u use
Oleksandr
hm...
joel
oh
Oleksandr
oh
don't hate me, this is just for games😂
joel
isee steam
Oleksandr
the four horsemen of the apocalypse
Oleksandr
joel
i need to try these games with wine
Victor D.
𝕵𝖔𝖘𝖚𝖊
/saved
𝕵𝖔𝖘𝖚𝖊
#ot
Shubham
Shubham
I am getting Segmentation Fault I can't identify where. Can someone see the code and tell me?
head is null
1
2
Shubham
head is null
Yes In linked list Head is null later new added new node will go to head
Shubham
I think there is something wrong in Insertnth()
I think there is something wrong in Insertnth()
call stack ... Node *head = new Node();
I think there is something wrong in Insertnth()
call stack 1... Node *head = new Node(); 2.... main 3... Insertnth(2, 69);
Shubham
Okay I will try it
maybe there are more problems with Insertnth😂😂😂
memory leak
point->next is null😕
Shubham
maybe there are more problems with Insertnth😂😂😂
Yes! But everything worked perfectly in my head 😂
Shubham
Shubham
memory leak
I made a pointer pointing to head so that I can traverse the list
Shubham
point->next is null😕
Point is pointing to head right? So it should traverse the list and point->next should store in point.. Any mistake here?
Explain
question 1 memory leak head addr is 0xabcd.... ... Node *point = new Node(); (if point addr is 0x12345......) point = head; (point addr change is 0xabcd) how release 0x12345...? ...
where is init next point?
Monoswee
https://bit.ly/2Jty4mb
Yashpal
https://paste.ubuntu.com/p/3F5KQpQ6yK
Shubham
☺️
Thanks! But I want to write by own to learn I won't open it until I solve mine 😂
Till
https://paste.ubuntu.com/p/3F5KQpQ6yK
printf("Sum of %d & %d is %d\n", A, B, C);
Dima
Dark souls code Visual souls 3
rakesh
/warn
Crescenzo
Someone who can explain how to compare two consecutive integers (subsequence) in a linked list? Example: 1, 2, 5, 13, 7, 8, 23 Output (with sum subsequence): 3, 5, 13, 15, 23 Thx!
Crescenzo
Language C.
Crescenzo
If you need it, I have a code designed by me, but I have a block on the consecutive comparison conditional..
Oleksandr
Why 1+2 and not 2+5?
Crescenzo
No, 1+2 and 7+8, sum of consecutive numbers (subsequence)..
Oleksandr
Ok, understand know(just don't know meaning of "consecutive")
Oleksandr
Give me your code
klimi
Give me your code too
Crescenzo
Ok sorry Alexander!
Crescenzo
The exercise asks me to eliminate consecutive elements (1,2,7,8) and replace them with their sum (1+2 and 7+8)
klimi
I love this chat
Crescenzo
struct elem { int info; struct elem *next; }; struct elem *readFile (FILE *fp, struct elem *top); void printList (struct elem *top); struct elem *writeFile (FILE *fp, struct elem *top); int main() { struct elem *top=NULL; FILE *fp; fp=fopen("inputFile.txt","r"); top=readFile(fp,top); fclose(fp); printList(top); fp=fopen("outputFile.txt","w"); writeFile(fp,top); fclose(fp); } struct elem *newelem (int info) { struct elem *nodo; nodo=(struct elem *)malloc(sizeof(struct elem)); if (nodo==NULL) return NULL; nodo->info=info; nodo->next=NULL; return nodo; } struct elem *insertList(struct elem *nodo, struct elem *top) { if (top==NULL) return nodo; top->next=insertLista(nodo, top->next); return top; } struct elem *readFile (FILE *fp, struct elem *top) { int info; struct elem *nodo; while (fscanf(fp,"%d",&info)>0) { nodo=newelem(info); top=insertLista(nodo,top); } return top; } void printList (struct elem *top) { while (top!=NULL) { printf ("%d -> ",top->info); top=top->next; } printf ("NULL"); } struct elem *writeFile (FILE *fp, struct elem *top) { int sum=0; struct elem *prec, *curr, *tmp; for (prec=top;prec!=NULL;prec=prec->next) { for (curr=prec->next;curr!=NULL;) { if (curr<prec && prec<curr) { tmp=curr; curr=curr->next; free(tmp); } else curr=curr->next; } { sum=sum+prec->info; fprintf (fp,"%d ",sum); } } return sum; }
Oleksandr
Are we need to handle smth like: input: 1 2 4 6 3 4 6 -> 7 6 -> 13 output: 13 ?
Crescenzo
The exercise also requires use of File, so I read from File, insert it in the list and the result I write it to File.
Anonymous
Check this...very basic implementation I wrote
Crescenzo
No Alessandro, consider this example: Example: 1, 2, 5, 13, 7, 8, 23 Output (with sum subsequence): 3, 5, 13, 15, 23
Crescenzo
Perfect, but I can't use other structures, only Linked LIST!
Anonymous
Check this...very basic implementation I wrote
Actually, sum=0 should be declared inside loop
Crescenzo
I had also thought of using a backing array, but it's not possible.
Anonymous
Perfect, but I can't use other structures, only Linked LIST!
Okay..I don't know much about data structures😭😭
Crescenzo
Yes I know, that part of the code was confusing, I wanted to give you an input.