I am not sure why my program is generating these errors. Line 24 especially since I worked with a tutor I did not expect these errors. What am I doing wrong. I know the program is not done and I am only on question 2 out of 5 for my homework, but am getting compiler errors already :( I will post the compiler errors below the code. Anything helps, really. Thank you
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#include <iostream>
using namespace std;
//Write a C++ function rotate(int arr[], int d, int n)
//that rotates arr[] of size n to the left by d elements
//Tutor explanation:
//1.find index
//2. in new indiex ** store in temp. **store index value in temp
//3. Assign current value to new index
//int d = 3
//int n = 7
// int arry[] = 0
void rotate(int arr[], int d, int n){
int array2[n]; //temporary array
int j = 0;
int i;
for(i=d;i<n;i++){
array2[j]=arr[i];
j++;
}
for(i=0;i<d;i++){
array[j] = arr[i];
j++;
}
//Swap happens here
for(i=0;i<n;i++){
arr[i] = array2[i];
}
}
//Given an array of random numbers, write a C++ function pushZerosToEnd(int arr[],int n)
//to push all the zero’s of a given array to the end of the array.
//Do not change the order of the non-zero elements
void pushZerosToEnd(int arr, int n){
int counter1;
int counter2;
int temp[8];
int j=8;
int k=0;
for(int i=0;i<8;i++){
if(arr[i] == 0){
temp[j] = arr[i]; //Starting from right side
j--;
}
else
{
temp[k]=arr[i];
k++;
}
}
}
//Given a linked list with at least two nodes...
//remove the last element from the linked list.
//Function prototype: Node* removeLastElement(Node* head)
Node* removeLastElement(Node* head){
//Code from another in class assignment
}
//Reverse a singly linked list.
//Function prototype: Node* reverseList(Node* head)
Node* reverseList(Node* head){
}
//Merge two sorted linked lists and return it as a new list.
// the new list should be made by splicing together
// the nodes of the first two lists.
//Function prototype: Node* mergeTwoLists(Node* n1, Node* n2)
Node* mergeTwoLists(Node* n1, Node* n2){
}
//In your main function...
//please give at least one test case for each of these five questions.
int main()
{
}
return 0;
| |
Homework1.cpp:24:3: error: C++ requires a type specifier for all declarations
array[j] = arr[i];
^
Homework1.cpp:45:8: error: subscripted value is not an array, pointer, or vector
if(arr[i] == 0){
~~~^~
Homework1.cpp:46:16: error: subscripted value is not an array, pointer, or
vector
temp[j] = arr[i]; //Starting from right side
~~~^~
Homework1.cpp:51:14: error: subscripted value is not an array, pointer, or
vector
temp[k]=arr[i];
~~~^~
Homework1.cpp:63:1: error: unknown type name 'Node'
Node* removeLastElement(Node* head){
^
Homework1.cpp:63:25: error: unknown type name 'Node'
Node* removeLastElement(Node* head){
^
Homework1.cpp:71:1: error: unknown type name 'Node'
Node* reverseList(Node* head){
^
Homework1.cpp:71:19: error: unknown type name 'Node'
Node* reverseList(Node* head){
^
Homework1.cpp:79:1: error: unknown type name 'Node'
Node* mergeTwoLists(Node* n1, Node* n2){
^
Homework1.cpp:79:21: error: unknown type name 'Node'
Node* mergeTwoLists(Node* n1, Node* n2){
^
Homework1.cpp:79:31: error: unknown type name 'Node'
Node* mergeTwoLists(Node* n1, Node* n2){
^
Homework1.cpp:94:1: error: expected unqualified-id
return 0;
^
12 errors generated.