Programming Articles - Page 2531 of 3366

A product array puzzle (O(1) Space) in C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

199 Views

Here we will see one interesting problem related to array. There is an array with n elements. We have to create another array of n elements. But the i-th position of second array will hold the product of all elements of the first array except the i-th element. And one constraint is that we cannot use the division operator in this problem. We have to solve this problem in-place without using any additional spaces.If we can use the division, operation, we can easily solve this problem, by getting the product of all elements, then divide i-th element of first array ... Read More

A data structure for n elements and O(1) operations?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

567 Views

Here we will see one data-structure with n elements, and O(1) operations. So the operations will take constant amount of time to execute.The data structure will hold n elements (from 0 to n-1). The data can be in any order. The Insertion, deletion and searching will take O(1) amount of time.To solve this problem, we will use one Boolean array. This will indicate that the item is present or not at position i. If the item is present, it will hold 1, otherwise 0.Algorithminitialization(n)begin    fill all elements of the Boolean array as 0 endinsert(i)begin    set element at index ... Read More

A C Programming Language Puzzle?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

502 Views

Here we will see one C programming language puzzle question. Suppose we have two numbers 48 and 96. We have to add the first number after the second one. So final result will be like 9648. But we cannot use any logical, arithmetic, string related operations, also cannot use any pre-defined functions. So how can we do that?This is easy. We can do by using Token Pasting operator(##) in C. The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the macro definition.Example Live ... Read More

How can we minimize/maximize a JFrame programmatically in Java?

Alshifa Hasnain
Updated on 15-Apr-2025 19:14:55

5K+ Views

In this article, we will learn to minimize/maximize a JFrame programmatically in Java. In Swing, programmers often need to resize the window as needed. For example, they can shrink the window when carrying out background tasks or expand the window size for a better full-screen experience. What is a JFrame? A JFrame class is a subclass of Frame class and the components added to a frame are referred to as its contents, these are managed by the contentPane. A JFrame contains a window with title, border, (optional) menu bar and user-specific components. By default, we can minimize a JFrame by ... Read More

A Boolean Matrix Question in C++?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

274 Views

Here we will see one interesting Boolean matrix problem. One Boolean matrix is given which contains 0’s and 1’s. Our goal is to find where 1 is marked. If the 1 is marked at position mat[i, j], then we will make all entries to 1 of the row i and column j. Let us see an example. If the matrix is like below −1 0 0 1 0 0 0 0 0 0 0 0 0 1 0 0Then after modification, it will be −1 1 1 1 1 1 0 1 1 1 0 1 1 1 1 1AlgorithmmatrixUpdate(matrix[R, ... Read More

2’s compliment for a given string using XOR ?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

950 Views

In this section we will see how we can find the 2’s complement using the XOR operation on a binary string. The 2’s complement is actually the 1’s complement + 1. We will use XOR operation to get the 1’s complement.We will traverse the string from LSb, and look for 0. We will flip all 1’s to 0 until we get a 0. Then flip the found 0.We will traverse from LSb. Then ignoring all 0’s until we get 1. Ignoring the first 1, we will toggle all bits using the XOR operation.Algorithmget2sComp(bin)begin    len := length of the binary ... Read More

1 to n bit numbers with no consecutive 1s in binary representation?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

503 Views

In this problem, we have to find some binary numbers which have no consecutive 1s. In a 3-bit binary string, there are three binary numbers 011, 110, 111, who have consecutive 1s, and five numbers are there which have no consecutive 1s. So after applying this algorithm for 3-bit numbers, the answer will be 5.If a[i] be the set of binary numbers, whose number of bits are i, and not containing any consecutive 1s, and b[i] is the set of binary number, where number of bits are i, and containing consecutive 1s, then there are recurrence relations like −a[i] := ... Read More

# and ## Operators in C ?

Vivek Verma
Updated on 12-Jul-2025 23:12:11

3K+ Views

In C, the "#" and "##" are the pre-processor operators that are used to convert a macro parameter to a String Literal. The macro parameters are the parameters of the macro definition, which are declared using the #define directive. The "#" operator is known as the Stringize operator, whereas the "##" operator is known as the Token Pasting operator. The #define Directive in C The #define directive is a preprocessor command that is used to create macros in the C programming language. Here is a syntax to create macros: #define MACRO_NAME replacement_text Or #define MACRO_NAME(param1, param2, …paramN) replacement_text ... Read More

attribute((constructor)) and attribute((destructor)) syntaxes in C in tutorials point ?

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

3K+ Views

Here we will see how to write a code where two functions are present, and one function will be executed before the main function, and another function will be executed after main function. These features are used to do some startup task before executing main, and some clean up task after executing main.To do this task we have to put attribute for these two functions. When the attribute is constructor attribute, then it will be executed before main(), and when the attribute is destructor type, then it will be executed after main().We are using GCC functions. The function is __attribute__(). ... Read More

How can we disable the cell editing inside a JTable in Java?

Alshifa Hasnain
Updated on 15-May-2025 11:25:24

5K+ Views

When working with JTables in Java Swing, there are many cases where one might need to display data that shouldn't be modified by users. In this article, we will learn to disable the cell editing inside a JTable in Java. JTable A JTable is a subclass of JComponent for displaying complex data structures. A JTable can follow the Model View Controller (MVC) design pattern to display the data in rows and columns. A JTable can fire TableModelListener, TableColumnModelListener, ListSelectionListener, CellEditorListener, and RowSorterListener interfaces. editCellAt() Method The editCellAt() method is used to prevent the JTable from editing a particular ... Read More

Advertisements