In a doubly linked list, also called a two-way list, each node is divided into three parts: The first part, called the previous pointer field, contains the address of the preceding element in the list. The second part contains the information of the list. The third part, called the next pointer field, contains the address of the succeeding element in the list. In addition, two pointer variables, named head and tail, are used that contain the address of first element and the address of last element of the list. Implementation Read More
Template
A template is one of the features added to C++ recently. It is a new concept which enables the programmer to define generic classes and functions; thus provides support for generic programming. Generic programming is an approach, where generic types are used as parameters in algorithms so that they work for a variety of suitable data types and data structures. A template can be used to create a family of classes or functions. For example, a class template for an array class would enable us to create arrays of various Read More
Merge Sort
Merging means combining elements of two arrays to form a new array. The simplest way of merging two arrays is to first copy all the elements of one array into a new array and then append all the elements of the second array to the new array. If you want the resultant array to be sorted, you can sort it by any of the sorting techniques. If the arrays are originally in sorted order, they can be merged in such a way as to ensure that the combined array is Read More
goto Statement
In programming, significance has always been given to use of structured programming technique to build reliable software that are easy to debug, maintain and modify. In some cases, performance is more important than strict obedience to structured programming technique. In these cases, some unstructured programming technique may be used. For example, we can use break to terminate execution of a repetition structure before the loop continuation condition becomes false. This saves unnecessary repetition of the loop if the task is completed before loop termination. Another instance of unstructured programming is Read More
Java Data Types
Data types in the Java programming language are basically divided into two groups – primitive data types and object references. A primitive data type is a basic building block and has full built-in support. Many other languages also support composite data types, which are build on a combination of primitive data types and may or may not have built-in support. Java Primitive Data Types Let’s discuss the available primitive data types in Java. There are 8 primitive data types in Java, which are Boolean, Char, Byte, Short, Int, Long, Float, Read More
Pointers and Arrays
Arrays and pointers are very closely linked together. In most contexts, C++ treats the name of an array as if it were a pointer i.e. memory address of some element. C++ interprets an array name as the address of its first element. That is, if age is an int array to hold 10 integers then age stores the address of age[0], the first element of the array. Consider the following code snippet: int *a ; // a is a pointer to an integer int age[10] ; cout<<"Enter the value for Read More
Doubly Linked List – Traversing and Search
Traversing a Doubly Linked List A doubly linked list can be traversed either way and that too very conveniently. Inorder traversal Reverse order traversal Inorder Traversal To traverse the doubly linked list, we walk the list from the beginning, and process each element until we reach the last element. .cf { font-family: Lucida Console; font-size: 9pt; color: black; background: white; } .cl { margin: 0px; } .cb1 { color: green; } .cb2 { color: blue; } .cb3 { color: maroon; } void traverseinorder(node *head) { while(head!=NULL) { printf(“%dn”,head->info); head=head->next; Read More
Integer Overflow
An integer overflow, or integer wrapping, is a potential problem in a program based upon the fact that the value that can be held in a numeric datatype is limited by the data type’s size in bytes. ANSI C uses the following minimum sizes: data type size (bytes) char 1 short 2 int 2 long 4 In practice, many compilers use a 4-byte int. It also should be noted that the actual ranges for the data types depend on whether or not they are signed. for instance, a signed 2-byte Read More
Java Servlet
A Java Servlet is basically used to extend the functionality of a server. A Servlet is a Java programming language class. It is used commonly to expand the functionality of an application hosted on web server. A Java Servlet adheres to the Java Servlet API in Java EE. Java Servlet API is a protocol that defines how a server request is handled by a Java class. A Servlet is majorly used over the HTTP protocol; however it is also equipped to communicate over any client-server protocol. A programmer can create Read More
Deleting an Element from a Heap
Deleting an Element from the Heap Deletion always occurs at the root of the heap. If we delete the root element it creates a hole or vacant space at the root position. Because the heap must be complete, we fill the hole with the last element of the heap. Although the heap becomes complete, i.e. it satisfies the shape property, the order property of heaps is violated. As the value that comes from the bottom is small, we have to perform another operation to satisfy the order property. This operation Read More
Share on: