Search
 
SCRIPT & CODE EXAMPLE
 

CPP

how to delete repeated element in stack c++

int* stack = (int*)malloc(10 * sizeof(int));
int size = 10;
int sp = -1;

bool isempty() {
    return (sp == -1);
}

bool isfull() {
    return (sp == size - 1);
}

void push(int x) {
    if (isfull()) {
        printf("Full!");
    }
    else {
        sp++;
        stack[sp] = x;
    }
}

int pop() {
    int x;
    if (isempty()) {
        printf("Empty!");
    }
    else {
        x = stack[sp];
        sp--;
    }
    return x;
}

void peek() {
    if (!isempty()) {
        printf("%d", stack[sp]);
    }
}

void clear() {
    while (!isempty()) {
        pop();
    }
}

void print() {
    if (!isempty()) {
        for (int i = 0; i < sp+1; i++) {
            printf("%d ", stack[i]);
        }
    }
    printf("
");
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: find a member variable in a vector of objects cpp 
Cpp :: lnk2001 unresolved external symbol __imp_PlaySoundA 
Cpp :: std 
Cpp :: how the theam are store in database 
Cpp :: distructor of the node of the link list 
Cpp :: castin in C++ 
Cpp :: 1491. Average Salary Excluding the Minimum and Maximum Salary leetcode solution in c++ 
Cpp :: set app icon qt 
Cpp :: left recursion program in c++ 
Cpp :: ue4 c++ oncomponentbeginoverlap 
Cpp :: 2d vector size c++ 
Cpp :: // A C++ program to show that we can use reference to 
Cpp :: The iostream is the head er file which contains all the functions of program like cout, cin and etc. 
Cpp :: pca compact trick 
Cpp :: qt widget list set selected 
Cpp :: The elements are store at contiguous memory locations in C++ 
Cpp :: initializer before void c++ 
Cpp :: hello command not printing in c++ 
Cpp :: operator = overloading c++ 
Cpp :: print number with leading zeros 
Cpp :: concatenate 2 vectors in c++ 
Cpp :: vector to char array c++ 
Cpp :: aliasing c++ 
Cpp :: what does for do in c++ 
C :: stop redis server 
C :: .gitkeep file 
C :: shuffle function in c 
C :: simplify fractions C 
C :: populate a map c++ 
C :: c concatenate strings 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =