Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask C/C++ Expert


Home >> C/C++

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;

}

C/C++, Programming

  • Category:- C/C++
  • Reference No.:- M9449942

Have any Question?


Related Questions in C/C++

Assignment word matchingwhats a six-letter word that has an

Assignment: Word Matching What's a six-letter word that has an e as its first, third, and fifth letter? Can you find an anagram of pine grave. Or how about a word that starts and ends with ant (other than ant itself, of ...

There are several ways to calculate the pulse width of a

There are several ways to calculate the pulse width of a digital input signal. One method is to directly read the input pin and another method (more efficient) is to use a timer and pin change interrupt. Function startTi ...

Software development fundamentals assignment 1 -details amp

Software Development Fundamentals Assignment 1 - Details & Problems - In this assignment, you are required to answer the short questions, identify error in the code, give output of the code and develop three C# Console P ...

What are the legal requirements with which websites must

What are the legal requirements with which websites must comply in order to meet the needs of persons with disabilities? Why is maximizing accessibility important to everyone?

Project - space race part a console Project - Space Race Part A: Console Implementation

Project - Space Race Part A: Console Implementation INTRODUCTION This assignment aims to give you a real problem-solving experience, similar to what you might encounter in the workplace. You have been hired to complete a ...

1 implement the binary search tree bst in c using the node

1. Implement the Binary Search Tree (BST) in C++, using the Node class template provided below. Please read the provided helper methods in class BST, especially for deleteValue(), make sure you get a fully understanding ...

Assign ment - genetic algorithmin this assignment you will

ASSIGN MENT - GENETIC ALGORITHM In this assignment, you will use your C programming skills to build a simple Genetic Algorithm. DESCRIPTION OF THE PROGRAM - CORE REQUIREMENTS - REQ1: Command-line arguments The user of yo ...

Question 1find the minimum and maximum of a list of numbers

Question: 1. Find the Minimum and Maximum of a List of Numbers: 10 points File: find_min_max.cpp Write a program that reads some number of integers from the user and finds the minimum and maximum numbers in this list. Th ...

Why do researcher drop the ewaste and where does it end

Why do researcher drop the ewaste and where does it end up?

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As