https://github.com/n4vrl0s3/delete-first-and-delete-last-function
Delete First and Delete Last Function (Python & C++)
https://github.com/n4vrl0s3/delete-first-and-delete-last-function
cpp delete-first delete-last python
Last synced: 2 months ago
JSON representation
Delete First and Delete Last Function (Python & C++)
- Host: GitHub
- URL: https://github.com/n4vrl0s3/delete-first-and-delete-last-function
- Owner: n4vrl0s3
- License: apache-2.0
- Created: 2024-12-27T00:23:17.000Z (6 months ago)
- Default Branch: master
- Last Pushed: 2025-03-17T01:18:17.000Z (3 months ago)
- Last Synced: 2025-04-05T19:08:03.843Z (3 months ago)
- Topics: cpp, delete-first, delete-last, python
- Language: C++
- Homepage:
- Size: 26.4 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# Delete First and Delete Last Function
This repository aims to provide a comprehensive starting point for understanding and implementing two fundamental list operations: deleting the first element and deleting the last element. These operations are implemented in Python and C++ and serve as a great introduction to list manipulation for beginners and intermediate programmers.
## Purpose of This Repository
### Deleting the First Element
Deleting the first element of a list is a basic operation that involves removing the element at the beginning of the list and shifting all subsequent elements one position to the left. This repository provides examples of how to perform this operation efficiently in Python and C++.
### Deleting the Last Element
Deleting the last element of a list is another essential operation that involves removing the element at the end of the list. This operation is straightforward and is commonly used in various programming tasks. This repository includes examples of how to handle this operation in Python and C++.
## Demonstration
Refer to the `program.py`, `Delete First.cpp`, and `Delete Last.cpp` files for complete demonstrations of the delete first and delete last functions in Python and C++.
### Python
```python
# Delete First Functionarr = [1, 2, 3, 4, 5]
print("Array before deleted:", arr)
arr.pop(0)
print("\nArray after deleted:", arr)
# Delete Last Function
arr = [1, 2, 3, 4, 5]
print("Array before deleted:", arr)
arr.pop()
print("\nArray after deleted:", arr)
```### C++
#### Delete First.cpp
```cpp
// filepath: /home/guan/Documents/Code/Delete-First-and-Delete-Last-Function/Delete First.cpp
#include
#include// Fungsi untuk menghapus elemen pertama pada array
void deleteFirst(int arr[], int n) {
for(int i=0; i
#include// Fungsi untuk menghapus elemen terakhir pada array
void deleteLast(int arr[], int n) {
if(n == 0) {
printf("Array kosong\n");
} else {
for(int i=n-1; i>0; i--) {
arr[i] = arr[i-1];
}
arr[0] = 0;
}
}int main() {
int arr[5] = {1, 2, 3, 4, 5};
int n = sizeof(arr)/sizeof(arr[0]);printf("Array sebelum delete: ");
for(int i=0; i## Features
- Simple and easy-to-understand examples
- Efficient list manipulation techniques
- Suitable for beginners and intermediate programmers
## Technologies Used
- Python
- C++
## Project Setup
1. **Clone the repository:**
```bash
git clone https://github.com/n4vrl0s3/Delete-First-and-Delete-Last-Function.git
```
2. **Navigate to the project directory:**
```bash
cd Delete-First-and-Delete-Last-Function
```
## Steps to Run
### Python
1. **Run the Python script:**
```bash
python program.py
```### C++
1. **Compile the C++ program:**
```bash
g++ program.cpp -o program
```
2. **Run the compiled program:**
```bash
./Delete First
```
```bash
./Delete Last
```
## License
This project is licensed under the Apache-2.0 License. See the [LICENSE](LICENSE) file for details.