if (x == 0) then // O(1) simple variable access
for i = 1 to n do // O(n)
a[i] = i; // O(1) simple variable access
Now, read this again until you understand it
if (x == 0) then // O(1) simple variable access
for i = 1 to n do // O(n)
a[i] = i; // O(1) simple variable access
Now, read this again until you understand it
Didn't you read any of the links I gave you? The very first one explains how to do it.
And you walked 10 miles everywhere...up hill...both ways, and you were thankful for it. ;)
And in snow up to my waist :)
Most of us older folks lived our entire lives without a phone attached to our bodies, so what we never had we never miss. I have a cell phone (not a smartphone) but rarely carry it with me. The only reason I even have the damned thing is so that I can have it in the car in case of an emergency. It came in handy a couple times for that. Otherwise for me it is just a useless toy.
If you have the entire line in a char array then just do this:
char line[255] = "B 127.2 Hi 183.2 Someone 23.8 Lost"
switch(line[0])
{
}
First you need to make a list of commands and associated functions that are to process them. Then you have several options, probably the simplest is to use a switch statement for each command
char command = 'B';
switch(command)
{
case 'A':
// do something
break;
case 'B':
// do something
break;
// etc.
}
line 9: what's the value of variable a???
line 20: what's the value of variable j??
Answer: both i and j are uninitialized variables, so their value can be any random number.
you did it wrong. look again at the examples I gave you.
line 67: it is not allocating enough memory -- need sizeof(struct node) instead of sizeof(struct node*) because it needs to allocate memory for the entire structure, not just a 4-byte pointer.
lines 69-79: q is now a ** pointer, and to reference an object of q is like this:(*q)->front=ptr;
or like this:*(*q).front=ptr;
And before using *q you need to check that it is not NULL, e.g.
if( *q == NULL)
{
*q = ptr;
}
else
{
// do stuff with *q here
}
The tile for the desktop is right in front of you after boot. It's in the lower-left corner. Just click on it. How much time does that take??? Windows 8 is a little bit of a learning curve, but not much. I hate the ribbons in MS Office more than I do Windows 8.
I don't like the Windows key on the keyboard -- I used a screw driver to knock it off because I am constantly hitting it while playing games. Too bad they didn't put the windows key somewhere else, like on the top row with the function keys.
also stated that we use the Start8 add-on to bring back the desktop,
Waste of time -- the desktop is already there. Just click the desktop icon on the metro screen.
If you use Ubuntu, and do not like their out of the box Unity interface, just load another. Hard to do that with Windows.
AFAIK you cannot do that with Windows -- no version of Windows allows that.
Notice how the Fox News pundits are claiming that "Obama just led us into a humilating defeat".
Huh? defeat from what war? I didn't know any was at war yet or that anyone won that war. In his speech last night Obama indicated Russia is going take some sort of diplomatic steps to alleviate the tension.
clock() returns milliseconds, time() returns seconds. If it's bubble sort then just to the bubble sort once instead of a million times as in my previous post. But you will have to give it a pretty large array so that the time is measurable. If the entire time to do the bubble sort is less than 1 millisecond then the measurable time will be 0.
You'd have to get a hook into the clock cycles of your computer
That would be going a bit to the extreme -- just using standard C function clock() and repeating the algorithm a million times would probably be sufficient.
clock_t t1,t2;
t1 = clock(); // get starting time
for(int i = 0; i < 1000000; i++)
{
// do algorithm here
}
t2 = clock(); // get ending time
int diff = t2-t1;
The President just made a TV speech in which he said he is not going to take any military action at this time. Russia is apparently willing to do some negotiating with Syria.
Can't help you until you post code.
that's interesting, the UK has no F-16s :)
And how do you know that?
In the first loop the j counter contains the value of the last concantinated string, so you want to copy the strings from i to j
for(; i < MAX_S_ROWS; j++, i++ )
{
strcpy(dest[j], dest[i]); // no clue what goes here
}
The remaining 8 are still where they always were -- at the end of all the strings you null'ed out which makes them unaccessable. In the concantination function you will need to move them just after the last concantinated string. You will have to put a 3d loop in that function between the two loops you already have.
If you contantinate 200 strings how do you wind up with 108 strings? The math doesn't add up.
Have you studies linked lists yet? This would be a lot easier to do if you could put the concantinated strings into a linked list. I have no idea where the other strings are, if you started out with 208 you should wind up with 104.
Same problem as I explained before. On line 68 what is the value of q ? Answer: NULL. You can't use a NULL pointer for anything because there's no memory assigned to it.
Also, in that same function, you need to pass q by address or by reference, not by value, so that the function can change the original pointer. You will have to make additional changes inside the insert() function.
struct queue *insert(struct queue** q, int val)
And change line 16 like this:
struct queue *insert(struct queue**, int);
line 41 change: (note: you don't need the q= assignment operator because insert() will do that.insert(&q,val);
line 22: there are not 108 elements in the array. You need to count the number of elements so that you can plug that number into the formula on line 22.
you need to declare j counter above and outside both loops. I don't see how it could break the display function.
The loop in ShuffleArray() need to be fixed too -- when that function starts there it not 208 elements in the array. Use the same loop that's in display function.
function create_queue() is attempting to dereference a NULL pointer. You don't need to call that function on line 23 because the pointer is already NULL.
for(int i=0, j = 0; i<208 && i<200; i+=2, ++j)
What's up with the i<208 && i<200? You only need one of those, not both. i<200 will prevent the loop from executing more than 200 times, so i<208 is useless code.
dest[i][0] = 0.0;
Careful with that because when i and j are the same value it will null out the string that it just finished concantinating. It would be a lot safer to do that in another loop
while( j < MAX_S_ROWS )
{
destination[j++][0] = 0;
}
Your loop to display the output is wrong. After concantination there are no longer 108 strings. One way to solve that is after concantination zero out the first byte of all the remaining strings, then when displaying them don't use 108 but check for destination[i][0] == '\0'
The main problem is that dest isn't big enough, some strings are longer than 13 characters. Increase the size of dest
char destination[208][25];
These my not work if dest is the same things as src1 (such as when i and j are both the same value in the loop). If that is the cast then you would only want to concantinate src2 to dest and ignore src1.
void myStrCat(char dest[], char src1[], char src2[] )
{
if( dest != src1 ) // compare the pointers, not the strings
strcpy(dest,src1);
strcat(dest,src2);
}
They both do the same thing -- its just how the object is declared. The -> is pointer notation. Some examples:
class MyClass
{
public:
int x;
};
// in this function pMyClass is a pointer, so it requires -> to
// reference any of it's objects
void foo(MyClass* pMyClass)
{
pMyClass->x = 0;
}
// in this function pMyClass is a reference which uses the . notation
void foo(MyClass& pMyClass)
{
pMyClass.x = 0;
}
int main()
{
MyClass mc;
mc.x = 0; // Neither a pointer nor a reference
MyClass* pmc = &mc;
pmc->x = 0; // This is a pointer and requires -> notation
MyClass& rmd = mc;
rmc.x = 0; // This is a reference so it requires . notation
yes, you didn't post it so I can't tell you how to change it.
The problem is in concantination function. The loop doesn't work right. After the first iteration the strings are
borndramatic dramatic insurance gravy release frying
Notice that dramatic is now in the list twice. When the first loop is finished the value of i is incremented from 0 to 2, which points to insurance. Now after the second loop iteration the strings are
borndramatic dramatic insurancegravy gravy release frying
This behavior is why after the shuffle some of the original strings are still there. I think what you need is another counter that tells where in the array the new strings should appear. In the code below myStrCat() had three parameters, not one. The first parameter is the destination, and the other two are the two strings to be concantinated. After the loop is finished you will have to null out all remaining strings in the array.
for(int i=0, j = 0; i<208; i+=2, ++j) // i < 208 concatenates all 208.
{
myStrCat(dest[j], dest[i],dest[i+1]); // myStrCat is equal to strcat().
// cout << dest[i] << " "; // outputs the first 100.
}
Agree -- Obama is treading on very thin ice. If he invades Syria he might be the one who gets outsted. That's why he would need the full support of Congress, and I doubt he will get it. American's are sick of constant wars over the past 10-15 years. We don't need to get involved in another no-win situation.
Just because you are big doesn't give you the right to push and bend other countries to your wil
Actually, it does. If it weren't for the USA and its allies the world would be in complete communist control today, or even worse under islomic control. The very worst kinds of governments are those based on some religion -- any religion will do. The USA in the 1700/1800s wasn't exactly kind to everyone, I'm thinking of the Christian witch hunts and destruction of native Americans.
There are three kinds of bullies in the world today. The good bullies are USA and its allies. Then there are the bad bullies, like China and Russia. Then the worst kind of bullies, Iran, Syria, etc which are all religious-based governments. And I won't forget all the African dictators either who also have killed thousands of their own people but we don't hear a lot about them today.
you will have to get the specs from the manufacturer how to get that info.
Can you change it to something that isn't your name and then back to your name?
I don't think so -- as I recall we only get one crack at changing the user name.
Can you get to other web sites on your computer? A few suggestions:
make sure your computer is always running antivirus program and a firewall.
clear your browser's catch and temp files. You should do this on a regular basis.
If that doesn't fix it delete all cookies and try to log in again
Download a program that checks for malware -- antivirus programs don't do that.
Depends. When a function returns a c++ class it will return a copy of the object, not the object iteself, so it doesn't matter if the original object is on the heap or the stack. If the function returns a POD array, such as char array then it must be declared in the heap because the array is not copied. When such an array is declared on the stack then the array is destroyed as soon as the function returns, making the array invalid. That is the cause of many difficult to find bugs.
So, we sell our old missiles to allies so that THEY, not us, can experience the 50% failure rate! Very nice of us, no?
No -- but an interesting question. I would think it would require a total rewrite of the program, unless there exists some program that will attempt to make that conversion. IMO the most difficult problem would be report writers -- COBOL has an excellent report writer that would be difficult to duplicate in other languages. Database, screens and other logic is probably not difficult to duplicate in another language.
How much does it really matter whether it is from gas, a bullet or a bomb, especially if you are an innocent civilian
I think how one dies does matter -- dying from gas can be pretty painful, dying from a bullet is almost instantanous. And what does it matter whether the dead were innocent civilians or militants? Dead is dead afterall.
The logic for all those functions is a little off. Look at quadFile() and trace in your mind what it is doing. Notice that there is only one instance of the variable x, y and z, yet the function is reading them multiple times without saving the values anywhere. You need to save all the values of x, y and z somewhere in either an array, linked list, or std::vector so that they can be used in the other functions.
Another way to do it without using an array is for quadFile() to read a line from the text file then call the other two functions. main() only calls one function -- quadFile(). Something like this
quadFile()
{
while( infile >> x >> y >> z)
{
double root1,root2;
CalcRoots(x,y,z,root1,root2);
numTable(x,y,z,root1,root2);
}
}
That function also had two while loops -- the one starting on line 25 is not needed because the loop on 28 will read all the values in the file until eof is reached. Delete the while loop that starts on line 25.
You need to pass the ifstream that is opened in main() to the function that needs to read the data.
int quadValues(ifstream& in, double &x, double &y, double &z)
And to the function that prints the results
int numTable(ofstream& out, double a, double b, double c, double &root1, double &root2)
Make sure to change the lines in main() that call those two functions. You can then delete the declarations of ifstream inside quadValue() and the declaration of ofstream in numTable() because they are not used.
There are no profits to be made by nuking Syria.
That sounds a bit like Quark from Star Trek :P)
The only reason the US wants to take Military action is to nuke the hell out of Syria,
Proof of that???
The security council and the UN should come up with a peaceful resolution without getting involved.
The UN is incapable of doing anything. Have you ever heard of the UN resolving any conflict anywhere in the world?
If you think Syria is a piss-ant sized nation, then why should we even bother to do anything.
Exactly!
US wouldn't be wormongeres if all the little piss-ant sized nations like Syria would cut all that crap out. Actually, seems to me I recall this all being started by Syrian people themselves.
? Arrest Asad and his high command for war crimes
Easier said than done. How do you plan to get through his army in order to arrest him??
You can't use strings in case statements -- only integers and single characters. If you need strings the only way to do it is with a series of if/else
statements.
"000\";
That is also wrong because the compiler will attempt to use \ as an escape character and out " as part of the string iteself. What you want is one of these two
"000\\"; // make \ part of the string
"000\""; // make " part of the string