Array stack, sorting HELP

What wrong with my codes? HELP please.

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
98
99
100
101
 #include "stdafx.h"
#include <iostream>
#include "iomanip"
#define STACK_SIZE 5
using namespace std;

int stackNum[STACK_SIZE];
int top=-1;

void pop();
void push(int);
void display();
void sort();



int main()
{
	while(1)
	{
	int choice;
	system("cls");
	cout<<"Push and Pop.\n";
	cout<<"========================\n";
	cout<<"[1]-Push\n";
	cout<<"[2]-Pop\n";
	cout<<"[3]-Display\n";
	cout<<"[4]-Sort\n";
	cout<<"[5]-Exit\n";
	cout<<"========================\n";
	
	cout<<"Enter your choice: ";
	cin>>choice;
	system("cls");
	switch(choice)
	{
	case 1:
		int num;
		cout<<"Enter a number to push: ";
		cin>>num;
		system("cls");
		push(num);
		break;
	case 2:
		pop();
		break;
	case 3:
		cout <<"Stack: \n";
		display();
		break;
	case 4:
		sort();
	case 5:
		exit(1);
	default:
		cout<<"\n -INVALID CHOICE!-\n";
	}
	cout<<endl;
	system("pause");
}
return 0;
}
void pop()
{
if(top==-1)
cout<<"\n Stack is Empty! \n";
else
cout<<"You removed: "<<stackNum[top--];
}

void push(int n)
{
if(top==STACK_SIZE-1)
cout<<"\n -STACK IS FULL- \n";
else
stackNum[++top]=n;
}

void display()
{
if(top==-1)
cout<<"\n Stack is Empty! \n";
else
for(int i=top;i>0;i--)

cout<<stackNum[i]<<endl;
}
void sort(int x[],int N)
{
	int Pass, I,Y;
	for (Pass = 1; Pass<N; Pass++)
	{

				Y = x[Pass];

			for (I = Pass-1; I >= 0 && Y < x[I]; I--)
				x[I+1] = x[I];

				x[I+1] = Y;
	}
}
i think its line 52.
What wrong with my codes?

You should know the errors and tell them to us

Is it:
1. Compiler error
2. Linker error
3. Unexpected behaviour
4. Unexpected results

Sure, we might see or test easily, but it is important that you learn to gather facts.
2 Errors

1. error LNK2019: unresolved external symbol "void_cdecl sort(void)"(?sort@@YAXXZ)referenced in function_main
2. fatal error LNK1120:1 unresolved externals
Last edited on
That is actually one error. It is a linker error.
void_cdecl sort(void)"(?sort@@YAXXZ)referenced in function_main


Function main calls void sort(). (Line 52, like anup30 said.)
The compiler was happy with the call, because line 13 declares that such function exists.

The linker, however, cannot find implementation for void sort() from any object file or library.

Your object file does contain implementation for a different, unused function void sort(int,int)
What should I need to change?
You need to resolve the discrepancies in how the sort function is used. Is it supposed to take an integer array and integer as parameters as you have definied in line 88?

line 13 - function prototype
void sort(); //no arguments expected in function

line 52 - function call
sort(); //no arguments sent to function

line 88 - function definition
void sort(int x[],int N) // function expects two arguments
is this correct?

line 13 - void sort();

line 52 - sort(stackNum, N);
Topic archived. No new replies allowed.