Curry
  • Curry
Why does my array print differently just by simply adding a useless printf?
Computer Science
  • Stacey Warren - Expert brainly.com
Hey! We 've verified this expert answer for you, click below to unlock the details :)
SOLVED
At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.
jamiebookeater
  • jamiebookeater
I got my questions answered at brainly.com in under 10 minutes. Go to brainly.com now for free help!
Curry
  • Curry
By having that printf statement, my code prints out the correct sorted array. without it, it acts weird. I read something about it not being synchronized, but how do i fix that?
Curry
  • Curry
@wio
Curry
  • Curry
any ideas wio? i've been stuck on this for so loong. :( also i need help writing an assembly method that gets the min value from an array. but this problem is my main focus rn.

Looking for something else?

Not the answer you are looking for? Search for more explanations.

More answers

anonymous
  • anonymous
I'm not sure. I don't see how the print statement would change anything.
Curry
  • Curry
should i take a screen shot of the different messages?
Curry
  • Curry
somewhere on stackoverflow it said that the printf has a synchonized(this) in its actual code. so, it lets the thread know it's the same.
Curry
  • Curry
and without it, the variables stay separate and get cached or something.
Curry
  • Curry
http://meta.stackoverflow.com/questions/269174/questions-about-threadloop-not-working-without-print-statement << this was the post. howeve,r i can't fix it evne reading this.
anonymous
  • anonymous
You're not using Java though, right? Also, are you doing a multi-threaded program?
Curry
  • Curry
i'm not sure. what is meant by a multithreaded program. i'm doing c.
Curry
  • Curry
I'm calling the insert functions many times, yes.
anonymous
  • anonymous
If it is a single threaded program, you don't need to worry about syncronization.
Curry
  • Curry
how do i know if it is multi-threaded prog?
anonymous
  • anonymous
It will create a thread. Something like pthread in C
Curry
  • Curry
well it seems like i am running a multi-threaded program then. i don't know where it says pthread, but it's not wokring without the print statement.
Curry
  • Curry
wait, would you happen to know how ot write basic assembly code?
anonymous
  • anonymous
If you haven't learned about threads yet, then you shouldn't be having a synchronization issue in your class.
Curry
  • Curry
we learned about threads in previous classes, but nothing was mentioned about it in this one.
Curry
  • Curry
but um, i'll try to figure this out. However, i really need help with writing an assembly code that gets the min value from an array. i know how to do arithmetic operations. however i do not know how to do get teh value. Any help?
anonymous
  • anonymous
I can help you come up with a better insert function.
Curry
  • Curry
ok!
anonymous
  • anonymous
``` void resize(list *ls) { ls->maxSize = ls->maxSize * 2; ls->sortedList = (int *) realloc(ls->sortedList); } int insert(list *ls, int val) { int position; // insert position int i; // index used for shifting array if (ls->size == ls->maxSize) { resize(ls); } // find the insertion position for (position= 0; position < ls->size; position++) { if (ls->sortedList[position] > val) { break; } } // shift the elements after insertion points over for (i = ls->size; i > position; i--) { ls->sortedList[i + 1] = ls->sortedList[i]; } // set array value ls->sortedList[position] = val; ls->size++; return position; } ``` You shouldn't check for a pointer to be `null`. Ultimately, you should never pass a null pointer into a function which requires a non-null value.
anonymous
  • anonymous
Hmmm, I think one line I put was wrong. ``` ls->sortedList[i + 1] = ls->sortedList[i]; ``` Should be ``` ls->sortedList[i] = ls->sortedList[i - 1]; ```
anonymous
  • anonymous
You should create a new question for your assembly thing.
Curry
  • Curry
ok!

Looking for something else?

Not the answer you are looking for? Search for more explanations.