please refer below C++ code
#include<stdlib.h>
#include<stdio.h>
typedef struct point
{
int x;
int y;
struct point *next;
}point;
//adding node to linked list
void add_node(point **head, point *node)
{
if(*head == NULL)
*head = node;
else
{
point *temp = *head;
while(temp->next != NULL)
temp = temp->next;
temp->next = node;
}
}
//squaring distance from origin
void square_distance(point *head)
{
point *temp = head;
int dist;
while(temp != NULL)
{
dist = (temp->x * temp->x) + (temp->y * temp->y);
//distance from origin
printf("%d\n", dist);
temp = temp->next;
}
}
int main()
{
int x,y;
point *head = NULL;
point *temp;
while(1) //infinite loop to scan infinite lines
{
scanf("%d %d", &x,&y);
if(x==0 && y ==0)
break;
temp = new point; //creating node
temp->x = x; //setting x field
temp->y = y; //setting y field
temp->next = NULL;
add_node(&head,temp);
}
printf("\n\n");
square_distance(head);
return 0;
}
please refer below output
5 6
4 4
1 3
1 0
0 2
-1 2
-2 0
0 -4
3 -1
0 0
61
32
10
1
4
5
4
16
10
Process returned 0 (0x0) execution time : 44.080 s
Press any key to continue.
In this exercise, you will make a struct that contains x and y coordinates: struct point...
You are given a pointer to a singly linked list. The singly linked list has cycles due to a programming error. Write a C program to detect whether the linked list has cycles without storing all the pointers to the nodes. The function detect_cycles should return 1 when a cycle is found and 0 when there are no cycles. Your code should handle all corner cases carefully and should not cause segmentation fault. Figure shows various examples of cycles for...
Using Python Create a simple linked list by defining a struct (in C/C++) or a class (in Python3). For example, in C/C++: struct singly_linked_list { int data; singly_linked_list *next; }; (Make sure you understand the concept of pointers - or lack thereof - in Python.) Write a function to determine if there is a cycle in the singly linked list. Return 1 if there is a cycle in the list, 0 if no cycle. This is a very common interview...
Write a complete program that: 1) declares two local integers x and y 2) defines a global structure containing two pointers (xptr,yptr) and an integer (z) 3) Declares a variable (mst) by the type of previous structure 4) requests the values of x and y from the user using only one scanf statement 5) sets the first pointer in the struct to point to x 6) sets the second pointer in the struct to point to y 7) uses the...
Project Description: In this project, you will combine the work you’ve done in previous assignments to create a separate chaining hash table. Overview of Separate Chaining Hash Tables The purpose of a hash table is to store and retrieve an unordered set of items. A separate chaining hash table is an array of linked lists. The hash function for this project is the modulus operator item%tablesize. This is similar to the simple array hash table from lab 5. However, the...
Using the provided Linked List example code, linkedlist.c, as an example Make a node struct that holds ints instead of strings. In your main, insert 25 to 75 random integers with range (0 to 100) into a linked list of your nodes. Use a random to determine how many to make. Write a function int sum(NodePointer current) that returns the sum of the integers in the list by looping through the linked list. Write a function int count(NodePointer current) that...
Creating linked list data structure Overview The purpose of this assignment is for you to write a data structure called a Linked List, which utilizes templates (similar to Java’s generics), in order to store any type of data. In addition, the nature of a Linked List will give you some experience dealing with non-contiguous memory organization. This will also give you more experience using pointers and memory management. Pointers, memory allocation, and understand how data is stored in memory will...
IN C ONLY As mentioned earlier there are two changes we are going to make from lab 5, The file you read into data structures can be any length. studentInfo array will be stored in another struct called studentList that will contain the Student pointer and current length of the list. Sometimes data can be used in structs that correlate between variables so it's convenient to store the data in the same struct. Instead of tracking a length variable all...
How can you change this function from the main program “struct point” to a “class point” into new .h and .cpp projects. Make all the member variables private. Add getter and setter methods for each member variable. ///////////////////////////////////////////////// struct point { int x,y;}; int main() { point plat[20]; for (int i=0;i<10;i++) { plat[i].x=rand()%400; plat[i].y=rand()%533; } /////////////////////////////////////////////////////////////
3. Polar Coordinates. (a) Given a rectangular coordinate point (x, y), how do you compute the equivalent polar coordinates: (r, 0)? (b) Given a polar coordinate (r, o), how do you compute the equivalent rectangular coordinate: (x, y)? (c) Consider the drawing in Figure 1. Compute the coordinate of each small circle. (d) What if the circle is centered at the point (cx, cy) (and not the origin). How does the formula change?
Please need help, programming in C
- Part A You will need to create a struct called Team that contains a string buffer for the team name. After you've defined 8 teams, you will place pointers to all 8 into an array called leaguel], defined the following way: Team leaguel8]. This must be an aray of pointers to teams, not an array of Teams Write a function called game) that takes pointers to two teams, then randomly and numerically determines...