answersLogoWhite

0


Best Answer

store the exor of the previous node address and next node address in each node of single linked list .further exor the nodes to proceed forward or backward as necessary

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you implement a doubly linked list using only one reference value instead of the usual next and previous references?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is difference between Deep copy and shallow copy?

A "shallow" copy is when the member values are physically copied from one object to another, *including* the values of any pointer or reference members. If there are pointer or reference memebrs, then, those poointers or references refer to the *same* objects as the original object, which is usually a bad thing. That's why you want to define a copy constructor and assignment operator for objects that contain pointers or references. It's called a "shallow" copy because only the values of the pointers/references are copied, instead of making copies of those referred-to objects and setting pointers to them. *That* is what would be called a "deep" copy, because it's going "deeper" into the structure, copying everything, not just the first "layer".


Describe why it is a bad idea to implement a link list version a queue which used the head of the list as the rear of the queue?

It isn't. In fact it is a very good idea. Since the list is circular, you need only maintain a reference to the tail (rather than the head), because the tail provides constant time access to both the head and the tail. In this way you get constant time insertions at the tail and constant time extractions at the head via a single reference -- exactly what you want from a queue. If the list were not circular, you would need two references, one to the head and one to the tail. That's a waste of memory when the tail has an otherwise redundant link that's always null. Point it at the head and refer to the tail instead of the head and you save memory.


Why in oscillator triode is used instead of transistor?

I do not understand your question, oscillators CAN be built with either (and many other amplifying components). A few examples are:triode tubetetrode tubepentode tubebeam power tubepentagrid converter tube (cathode and first 2 grids form local oscillator)magnetron tubeklystron tubetraveling wave tubethyratron tubeneon lamppoint contact transistorjunction transistorsurface barrier transistorfield effect transistortunnel diodeunijunction transistorsilicon controlled rectifiermagnetic amplifierFERRACTORoperational amplifier ICtimer IClogic inverter ICetc.Perhaps you meant why it was in some specific circuitthat you don't give any reference to. If this is the case, I cannot answer without a reference to the specific circuit. One possibility for selecting a tube instead of a transistor to implement an oscillator would be that it must deliver higher power and/or voltage than a transistor is capable of.


Detail about independence reference in c plus plus?

An independent reference (or simply a reference) is an alias to an existing reference. int a = 42; int& ref = a; // independent reference In the above code, ref is a reference to the object named a. If you modify the value of ref then you modify the value of a -- they are one and the same object. This can be proved as follows: ref *= 2; // double the value of ref assert (a==84); // verify a has also doubled References are a bit like constant pointers. That is, once assigned, they cannot be reassigned, they must always refer to the same object, just like a constant pointer: int* const ptr = &a; The difference is that a pointer (even a constant pointer) is a variable and therefore requires memory of its own to store the memory address of the object being pointed to. A reference does not; a reference is simply an alias -- an alternate name for an object. Also, unlike a pointer, a reference cannot be null -- it must always refer to something valid. Moreover, the object it refers to must be guaranteed to outlive the reference itself. For example: int* ptr = new int(42); int& bad_ref = *ptr; // refer to the object pointed to by ptr (the int with value 42) delete ptr; At this point, what is bad_ref referring to? The integer pointed to by ptr no longer exists (we just deleted it), so bad_ref is now referring to memory that no longer belongs to our program. The value may still exist at the original memory location, but now the memory is released to the system, any external process can modify that memory behind our backs. Thus any future attempt to access that memory via bad_ref would result in undefined behaviour. Therefore never refer to dynamic memory unless you are absolutely certain that memory will outlive the reference. Reference are predominantly used when passing objects to functions by reference. Passing by reference can be achieved either by passing a pointer or passing a reference. But in cases where a pointer must be non-null and the pointer must be constant, passing by reference is the preferred option. Consider: void f1 (int* const p) { if (p) { *p *= 2; // double the value being pointed at. } } Every time we call this function we must test p to ensure it is non-null before we can access the memory being pointed at. If we pass by independent reference instead, we can eliminate the unnecessary test: void f2 (int& r) { r *= 2; // double the value being referred to by r } Can we always be certain r never refers to a null object? No, we cannot. Consider the following: int main() { int* p = nullptr; f1 (p); // OK f2 (*p); // unhandled exception: access violation! } You might ask where's the benefit, but the benefit comes from the calling convention itself. Function f2() expects a non-null reference therefore that is exactly what we should pass. *p is an invalid reference because p is a nullptr, so the problem is not the function, it is the caller. Although function f1() can handle invalid references gracefully, the point is that we don't want to pass invalid references to this particular function at all, and f1() does not alert us when we do. If an exception occurs then the program is invalid, so the exception forces us to rectify that. In this manner we achieve more robust and efficient code. If a reference argument is optional, then of course a pointer makes more sense (typically defaulted to nullptr). Similarly if we need to refer to different objects through the same pointer argument (non-const pointer). But when a reference is not optional and must refer to the same object, an independent reference makes the most sense.


What is reference variable in c plus plus?

A reference is not a variable of any kind. A reference is simply an alias; an alternate name for an object that already exists. It is analogous to a person with the birth name Robert who might also be known as Robbie, Rob, Rab, Bob and so on. They are all aliases for the same person, so every operation we perform on Bob or Robbie is actually performed on Robert. Once we assign an object to a reference, we cannot subsequently assign another object to that same reference. Thus a reference is always guaranteed to refer to the same object for as long as that reference remains in scope. Moreover, a reference can never be null; it must always refer to something. As such, references must be assigned to an object at the point of declaration, just as you would a constant. Note that although a reference is not a variable, the object it refers to can be, unless the reference itself is explicitly declared constant. By the same token, a non-constant reference cannot refer to a constant object. References are typically used whenever we need to pass an object to a function by reference rather than the usual by value semantics. Like so: void by_value (int x) {} void by_reference (int& y) {} In the above examples, x is a copy of the object we pass to the function, so any changes made to x will not affect the object we passed. However, y is a reference thus any changes made to the object referred to by y will be reflected in the object we passed. A pointer variable is also a type of reference, but it behaves quite differently. Firstly, a pointer variable really is a variable; it is used to store a memory address thus it requires memory of its own. Secondly, unless the pointer is declared constant, we can change the address a pointer refers to by changing its value. Finally, a pointer may be null. References are generally much easier to work with and more intuitive than pointers. For instance, we do not need to dereference a reference, thus we can use the member-of operator (.) rather than the pointer-to-member operator (->) when working with object references. Moreover, given that a reference can never be null, there is no need to test for null as we would with a pointer. When passing an object by reference, the function can simply use the reference, safe in the knowledge the reference refers to a valid object. If we pass a pointer, we lose that guarantee and must test the pointer before attempting to dereference it. Nevertheless, there can often be cases where passing an object to a function is optional, in which case we use a pointer argument defaulting to null. There is also one other type of reference known as an r-value reference. An r-value is an operand that appears on the right-hand-side of an operator. Typically, an r-value is a constant since we would normally expect to only modify the left-hand-operand (the l-value). However, since C++11, move semantics require that an r-value be modifiable. For that reason we use r-value references. We typically use r-value references when declaring move constructors and move assignment operators, like so: struct S { S (const S&); // copy constructor S& operator= (const S&) // copy assignment S (S&&); // move constructor S& operator= (S&&) // move assignment } Note that S& is a reference while S&& is an r-value reference. The reason we need an r-value reference is that r-values that are moved are always assumed to be objects that will shortly fall from scope (such as when return an object by value). Thus move semantics must leave the r-value in an unspecified but valid state in order to allow the object to be destroyed. To achieve that, the r-value must be modifiable, hence we use an r-value reference. The classic scenario is when moving a vector. Copying vectors is highly inefficient, but moving them is simply a case of switching ownership of the resource being moved; the array itself. Once the l-value has taken ownership of the resource, the r-value can simply be switched to an empty state. Note that we don't actually clear the vector (the resource no longer belongs to the r-value) we simply change its internal to state to reflect that of an empty vector. The vector can then be allowed to safely fall from scope. It should be noted that the C++ compiler may well implement references as constant pointers and r-value references as pointer variables, however that is a matter of concern only to compiler designers. When programming in C++, it is vital that we understand that a pointer is a type while a reference is a programming tool.

Related questions

What is the way to verify that a formula references the cells you want it to reference?

Use absolute references. e.g. $B$12 instead of just B12.


Is it ever okay for your references to contact a potential employer instead of them contacting your references?

If your reference has a prior relationship with the potential employer then the contact would make sense. If not, no.


What is an easy way to verify that a formula references the cells that you want it to reference in excel?

Use absolute references (e.g. $C$3) instead of relative references (e.g. C3). See related questions for more information about absolute references.


What characters is used in Excel to change a relative cell reference to an absolute cell reference?

The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.The $ is used to make a mixed or absolute reference.A1 is a relative reference.$A1 and A$1 are mixed references.$A$1 is an absolute reference.


What is a bibilyography?

References. Bibliography is another word for references, but most people nowadays just use Bibliography instead of References.


Cell references formulas should be used in worksheets instead of?

Cell references should be used where possible instead of having actual values in a cell.


Can you ask a prospective employer to see references that have been submitted to them I have gone on a lot of interveiws and thought I had the position only in the end to get rejected.?

Normally, reference is made privately. When employers talk to the references that you provide, those are private conversations between the employer and your reference. You would likely have better luck asking your reference what s/he has told the prospective employer instead. As a general rule, the reference you provide is likely to provide "good" details about you. If you are rejected nonetheless, why would you suspect your reference(s) sabotage you, other than that you're just not good enough for the job, or that the interviewer(s) just don't like your face?


How can insert a row in excel sheet without changing the formula?

Change the formula to use absolute references instead of relative references. Instead of =A2+B3, use =$A$2+$B$3.


Does Vlad Dracula and Bram Stoker Dracula common?

Bram (Abraham) Stoker did try and make strong reference between Count Dracula and Vlad Tepes Dracula in his book but the references he gave were erroneous so instead of making a strong connection between the two he instead gave Vlad an alibi.


What are the disadvantage of using formula in excel instead of using cell reference?

Using a formula which does not reference any cells means that the result is fixed, as the values are fixed. The result will only change if the formula is changed. Using cell references allows you to have a formula using variables. If the data changes then the result of the formula changes. The question is a little odd however because it is almost certain you will want to, and are able to, use both; cell references within formulas.


Is 115 BC in the second century?

No, it is in the second century BC. As a general rule, if you do not specify BC or AD, the assumption is that you are talking about AD. Some use BCE and CE to reference 'Before Common Era' and 'Common Era' instead of the references to Christ.


How pointers are used in java?

They aren't. Java uses the (safer) idea of references instead of pointers.