Struct complex

Assignment Help C/C++ Programming
Reference no: EM13159816

A complex number can be represented by two parts, real and image. A series complex data can be organized as a group of elements by linked list, which is shown as below: struct Complex

{

float real; float image;

struct Complex *next;

};

  1. Complete the following functions.

struct Complex* Generate (float a, float b)

{

// return one new Complex node

}

void Push (struct Complex **source, struct Complex *newNode)

{

// create linked list data by "stack" creation,

// insert the newNode into the head of source.

// (backward linked list creation)

}

void Print (struct Complex *source)

{

// print out all linked list data as the form, A+Bi,

// and the related distance, |A+Bi|

}

  1. Complete the following functions.

void FrontBackSplit (struct Complex* source, struct Complex** front, struct Complex** back)

{

// Split the nodes of the given list into front and back halves,

// and return the two lists using the reference parameters.

// If the length is odd, the extra node should go in the front list.

// You will probably need special case code to deal with the

// (length <2) cases.

}

void Sort (struct Complex **source)

{

// sort the data of linked list source in increasing order of

// complex number distance

}

  1. Complete the following functions.

struct Complex* AppendMergeReal (struct Complex* source1,

struct Complex* source2)

{

// Merge two complex linked lists (source1 and source2) into

// union of real part of source1 and source2.

// For example, real part of source1 are {1 2 3 3 5}, and real part

// of source2 are {2 3 5 8 8 9}, the merged result are {1 2 3 3 5 8 8 9}.

}

  1. (Bonus) Complete the following functions.

void RecursiveReverse (struct Complex** source)

{

// Recursively reverses the given linked list by changing its .next

// pointers and its head pointer in one pass of the list.

}

Please verify your program by following test code

int main()

{

float data1_real[11]   = {3, 2, -5, -9,   7, 9, 4, -2,   4, -7, -7};

float data1_image[11] = {7, -8, -7, 5, -2, 4, 4, 3, -6, 7, 9};

struct Complex *newNode;

struct Complex *source1 = NULL, *dest = NULL;

struct Complex *front, *back; char c;

// Generate Complex data linked list with data1 for (int i=0; i<11; i++) {

newNode = Generate(data1_real[i], data1_image[i]); Push(&source1, newNode);

}

// print out complex data of source1 printf("Original data of source1:\n"); Print(source1);

// use FrontBackSplit() to divide source1 data into front part

// and back part, and print out these two split data FrontBackSplit(source1, &front, &back); printf("\nFront part:\n");

print(front); pritf("\nBack part:\n"); print(back);

// sort input complex data according to the distance

// and print out sorted data of front and back individually printf("\nSorted front part:\n");

Sort(&front); Print(front);

printf("\nSorted back part:\n"); Sort(&back);

Print(back);

printf("\n=====================================================\n");

// sorted data according to real part

float

data2_real[6] = { 2,

3,

5,

9,

9, 9};

float

data2_image[6] = { 7,

-8,

-7,

5,

-2, 4};

float

data3_real[8] = { 3,

4,

5,

5,

6, 8, 9, 9};

float

data3_image[8] = {-8,

5,

-2,

4,

7, 9, 3, 4};

struct Complex *source2 = NULL, *source3 = NULL; struct Complex *result;

// Generate Complex data linked list with data2 and data3 for (int i=5; i>=0; i--) {

newNode = Generate(data2_real[i], data2_image[i]); Push(&source2, newNode);

}

for (int i=7; i>=0; i--) {

newNode = Generate(data3_real[i], data3_image[i]); Push(&source3, newNode);

}

// Verify AppendMergeReal() function and print out the result printf("\nOriginal data of source2:\n");

Print(source2);

printf("\nOriginal data of source3:\n"); Print(source3);

printf("\nMerged data of source2 and source3:\n"); result = AppendMergeReal(source2, source3); Print(result);

// Reverse merged data of source2 and source3 and print out the result printf("\nReverse test (merged data):\n"); RecursiveReverse(&result);

Print(result);

getch(); return 1;

}

Reference no: EM13159816

Questions Cloud

Access control models : Compare and contrast access control models. Select an access control model that best prevents unauthorized access for each of the five scenarios given below
Importance of making critical evaluations of news stories : Write a 350- to 700-word paper clarifying the importance of making critical evaluations of news stories. Use the following questions to help develop your paper:
How natural selection works on individuals : Include a real or hypothetical example ofthe process of natural selection in your answer other thaninsects and insecticide!Identify the specific natural selection pressure and the specifictrait being selected for in your example.
Explain what is the overall order of the reaction : A reaction in which A,B ,C and react to form products is first order in A, second order in B, and zero order in C. What is the overall order of the reaction?
Struct complex : A complex number can be represented by two parts, real and image. A series complex data can be organized as a group of elements by linked list, which is shown as below: struct Complex
Run in the forward direction to restablish equilibrium : Run in the forward direction to restablish equilibrium. B. Run in the reverse direction to restablish equilibrium. C. Remain the same. Already at equilibrium. The concentration of CO will: A. Increase. B. Decrease. C. Remain the same
Design the logic for a program : Using Visual Logic: Design the logic for a program that allows a user to entry 15 numbers, then displays each number and its difference from the numeric average of the numbers entered.
What is the maximum mass of molybdenum : The elements silver, molybdenum, and sulfur combine to form Ag2MoS4. What is the maximum mass of Ag2MoS4 that can be obtained if 8.63 g of silver
Define and explains an open system : Defines and explains a closed system and provides an example. Defines and explains an open system and provides an example. Explains the inner and outer flows of a closed system. Explains the inner and outer flows of an open system.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Program to check compatibity for matrix multiplication

Write down program in C++ for matrix multiplication. Program must accept dimension of both matrices to be multiplied and check for compatibity.

  Program to compute and show miles per gallon

Create the program in C++ which will input miles driven and gallons used (both as integers) for each tankful. Program must compute and show miles per gallon.

  Program to compute the total volume

Write a program to compute the total volume for a number of cylinders. A cylinder may have different values for height and radius.

  Write a very basic doubly-linked list

CptS 122 Lab #2: Linked Lists ,  Along with vectors, linked lists are one of the fundamental data structures in computer science. Unlike vectors, which store information in a contiguous block of computer memory, linked lists have the potential to sto..

  Array of integers declared-initialized to number of tickets

Array of integers named parkingTickets has been declared and initialized to number of parking tickets given out by city police each day as beginning of current year.

  Use structures to create c program to compute student record

Explain the following and give their suitable syntax. A pointer. Use structures to create C program to compute and store student records of class.

  Write program to count occurrences of each word in text

Write down C++ program to read following text. Count occurrences of each word in text and keep this count in list of elements containing (word, occurrence count) pairs.

  Write a program using vectors and iterators

Create a program that uses at least two functions that will be called from your main. This program is a number game program that asks for parts of your phone and after manipulating it mathematically, eventually outputs your entire phone number. The d..

  Allows the user to enter the coefficients for a system

Create a graphical (not text-based) Visual C++ program that allows the user to enter the coefficients for a system of four equations with four unknowns. Include a button that when clicked, will solve the system of equations and display the results in..

  Represent an instruction supported by simpletron

Implementation contains a Simpletron class and several supporting Instruction classes

  Write short c program to develops two processes

Write down a short C program which develops two processes. Each process must repeatedly write its own unique message to test file, one character at time. Do you see garbled messages in the file? Explain why or why not?

  Ruby implement primitive types

How does Ruby implement primitive types, such as those for integer and floating-point data?  3-What is the single most important practical difference between Smalltalk and C++?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd