please help me to answers this question about C++.....huuhuhuhu
1) Write a full program for the bubble sort algorithm. User is required to enter specific input numbers and the program will be able to sort the given numbers in ascending order. Write down in a table the time (according to your system clock) that it takes for the program to complete. You may do this by running the program for several values of input.
Hints:
a) Write full source code
b) Use system clock to measure the running time
c) Use several input (eg: N = 100 , N = 1000 , N = 10000, N = 100000 etc)
d) Have access to a file (to store your running time)
2) What is the difference between static and dynamic memory allocations? List advantages and disadvantages for the both type of memory allocations.
3) Use structure to wrap student information (such as Matrix Number, name and MTS 3023 mark) and manipulate it by reading information to an array of student structure and print them on to console screen.
4) The common error message which might encounter in your program is ?memory access violation? or ?segmentation violation?. What does it mean? How to avoid it?
5) For each of the following four program fragments:
a. Give an analysis of the running time (Big-Oh)
b. Implement the code and give the running time for several values of N
c. Compare your analysis with the actual running times
View Answers
October 4, 2011 at 12:05 PM
C++ Bubble Sort
#include <iostream>
using namespace std;
void sort(int ar[], int size)
{
int temp;
for(int i = 0; i < size; i++)
for(int j = 0; j < size - i - 1; j++)
if(ar[j] > ar[j + 1])
{
temp = ar[j];
ar[j] = ar[j + 1];
ar[j + 1] = temp;
}
}
int main()
{
int *array;
int size;
cout << "Enter size of array: ";
cin >> size;
array = new int[size];
for (int x = 0; x < size; x++)
{
cout << "Enter value for index " << x + 1 << ": ";
cin >> array[x];
}
cout << "Before sorting: ";
for (int i = 0; i < size; i++)
{
if (i == (size - 1))
cout << array[i];
else
cout << array[i] << ", ";
}
sort(array, size);
cout << "\nAfter sorting: ";
for (int j = 0; j < size; j++)
{
if (j == (size - 1))
cout << array[j];
else
cout << array[j] << ", ";
}
cin.ignore();
cin.get();
delete array;
return 0;
}
October 4, 2011 at 12:24 PM
Difference between Static and Dynamic Memory Allocation:
1)Dynamic memory allocation is at runtime. static memory allocation is before run time, but the values of variables may be changed at run time.
Static memory allocation saves running time, but can't be possible in all cases.
2)Dynamic memory allocation stores it's memory on heap, and the static memory allocation stores it's data in the "data segment" of the memory.
Ads
Related Tutorials/Questions & Answers:
Advertisements
please help me to solve this question about array
please help me to solve this
question about array write a program...() > 1)
System.out.println("It is not character.
Please enter...();
if (brr.length() > 1)
System.out.println("It is not character.
Please
please help me.
please help me. How to move the edits.jsp in below link?
http://www.roseindia.net/
answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html
please help me.
please help me.
Please send
me the validation of this below link.
the link is http://www.roseindia.net/
answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search-and-Edit.html
Thanks
Trinath
Please help me.
Please help me. Hi i am trinath in below there is a url.In that url there is a code of edit a jsp page.I understand that code but only one thing i...://www.roseindia.net/
answers/viewqa/JSP-Servlet/9584-JSP-Servlet-Search
help me please
help me please Hello
I want helping for this
question ,
Please
Write a program that reads some friends� names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
please help me.
please help me. I have three table in mysql,and i hava create a excel sheet and add this sheet.but my
question is in every sheet i can display one one table result.how can i do
please help me.
please help me.
Please send
me a code of template in opencms and its procedure.so i can implement the code.
Thanks
trinath
please help me.
please help me. How to read a properties file in java with a suitable example.
Please send
me.
Thanks
Trinath
Please visit the following link:
Java read properties file
urgent...pleAse help me.....please!
urgent...
pleAse help me.....
please!
please help me urgent! how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
please help me.
please help me. I have a jsp page under that i add a list box under i get the countries through my database.
so how can i do
please help me
before. This name list should get from the database.
Please help me.
By the way, I'm...
please help me Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another
please help me...
please help me... write an application that print number in the following order using a FOR-Loop
1 2 3 4 5
2 4 6 8 10
3 6 9 1215
4 8 121620
5 10152025
please help me in these prog
please help me in these prog
create 2 jdbc programs including awt
create 2 jdbc programs including swing
create 2 jdbc programs including command line argument
create 2 jdbc programs including io class
4 jdbc prog using
please help me to this problem..
please help me to this problem.. i wrote a program like keyboard... inside the JTextField) but i want to make this program to let
me write where i clicked (i.e allows
me to write any thing at the field where i clicked
Please help me out
Please help me out
Description* You are hired to develop a laptop inventory information system for Sheridan College in order to keep track of the information
about the laptops lent to the students. Users can add or remove data
Please help me
Please help me program for when a user enter his card number, it has to create default security pin in the database
please help me
please help me interface Test1 { String toString(); }
public class Test {
public static void main(String[] args) {
System.out.println(new Test1() {
public String toString() { return "test
Please help me
Please help me Hi Sir,
please send
me the code for the following progrems...
1) all sets are integer type:
input:
set1={10,20,30,40}
set2={15,25,35}
output:
union={10,15,20,25,30,35,40}
2) input: "Hi what
please help me?
please help me? Define a class named Circle with the following properties:
List item
An integer data field named radius with protected access modifier, and a String data field named colour with private access modifier. Both
Please help me??
Please help me?? Question_1: Using one-dimension array of primitive type elements.
Objective: The purpose of this lab exercise is to practice how to declare, create and manipulate a one-dimension array of primitive type
help me please
help me please how can i do dictionary with the use of array code in java, where i will type the word then the corresponding meaning for that word will appear...thanks
please help me
please help me how to use two browse buttons, one browse button for displaying the first image and second for the second image along with its file path and also to display text file along with its path using layouts or panels
please help me
please help me how to use two browse buttons, one browse button for displaying the first image and second for the second image along with its file path and also to display text file along with its path using layouts or panels
please help me here
please help me here
please show
me how can this show the right output that i need
please continue doing this program using only if else and do while
please please"
here is the problem
Automatic Teller Machine [B] Balance [D
please help me here
please help me here
please show
me how can this show the right output that i need
please continue doing this program using only if else and do while
please please"
here is the problem
Automatic Teller Machine [B] Balance [D