Convert the above java code to C code ?
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
public class DynamicArray {
private int array[];
private int count;
private int size;
public DynamicArray()
{
array = new int[1];
count = 0;
size = 1;
}
public void add(int data)
{
if (count == size) {
growSize(); // make array size double
}
array[count] = data;
count++;
}
public void growSize()
{
int temp[] = null;
if (count == size) {
temp = new int[size * 2];
{
for (int i = 0; i < size; i++) {
temp[i] = array[i];
}
}
}
array = temp;
size = size * 2;
}
public void shrinkSize()
{
int temp[] = null;
if (count > 0) {
temp = new int[count];
for (int i = 0; i < count; i++) {
temp[i] = array[i];
}
size = count;
array = temp;
}
}
public void addAt(int index, int data)
{
if (count == size) {
growSize();
}
for (int i = count - 1; i >= index; i--) {
array[i + 1] = array[i];
}
array[index] = data;
count++;
}
public void remove()
{
if (count > 0) {
array[count - 1] = 0;
count--;
}
}
public void removeAt(int index)
{
if (count > 0) {
for (int i = index; i < count - 1; i++) {
array[i] = array[i + 1];
}
array[count - 1] = 0;
count--;
}
}
public static void main(String[] args)
{
DynamicArray da = new DynamicArray();
da.add(1);
da.add(2);
da.add(3);
da.add(4);
da.add(5);
da.add(6);
da.add(7);
da.add(8);
da.add(9);
System.out.println("Elements of array:");
for (int i = 0; i < da.size; i++) {
System.out.print(da.array[i] + " ");
}
System.out.println();
System.out.println("Size of array: " + da.size);
System.out.println("No of elements in array: " +
da.count);
da.shrinkSize();
System.out.println("Elements of array "+
"after shrinkSize of array:");
for (int i = 0; i < da.size; i++) {
System.out.print(da.array[i] + " ");
}
System.out.println();
System.out.println("Size of array: " + da.size);
System.out.println("No of elements in array: " +
da.count);
da.addAt(1, 22);
System.out.println("Elements of array after" +
" add an element at index 1:");
for (int i = 0; i < da.size; i++) {
System.out.print(da.array[i] + " ");
}
System.out.println();
System.out.println("Size of array: " + da.size);
System.out.println("No of elements in array: " +
da.count);
da.remove();
System.out.println("Elements of array after" +
" delete last element:");
for (int i = 0; i < da.size; i++) {
System.out.print(da.array[i] + " ");
}
System.out.println();
System.out.println("Size of array: " + da.size);
System.out.println("No of elements in array: " +
da.count);
da.removeAt(1);
System.out.println("Elements of array after"+
" delete element at index 1:");
for (int i = 0; i < da.size; i++) {
System.out.print(da.array[i] + " ");
}
System.out.println();
System.out.println("Size of array: " + da.size);
System.out.println("No of elements in array: " +
da.count);
}
}
Convert the above java code to C code ?
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 2 steps
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education