mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-23 18:12:47 +08:00
formatting source-code for 153fb7b8a5
This commit is contained in:
@@ -5,25 +5,22 @@
|
||||
using namespace std;
|
||||
|
||||
/* Constructor */
|
||||
cll::cll()
|
||||
{
|
||||
cll::cll() {
|
||||
head = NULL;
|
||||
total = 0;
|
||||
}
|
||||
|
||||
cll::~cll() { /* Desstructure, no need to fill */ }
|
||||
cll::~cll() { /* Desstructure, no need to fill */
|
||||
}
|
||||
|
||||
/* Display a list. and total element */
|
||||
void cll::display()
|
||||
{
|
||||
void cll::display() {
|
||||
if (head == NULL)
|
||||
cout << "List is empty !" << endl;
|
||||
else
|
||||
{
|
||||
else {
|
||||
cout << "CLL list: ";
|
||||
node *current = head;
|
||||
for (int i = 0; i < total; i++)
|
||||
{
|
||||
for (int i = 0; i < total; i++) {
|
||||
cout << current->data << " -> ";
|
||||
current = current->next;
|
||||
}
|
||||
@@ -33,22 +30,17 @@ void cll::display()
|
||||
}
|
||||
|
||||
/* List insert a new value at head in list */
|
||||
void cll::insert_front(int new_data)
|
||||
{
|
||||
void cll::insert_front(int new_data) {
|
||||
node *newNode;
|
||||
newNode = new node;
|
||||
newNode->data = new_data;
|
||||
newNode->next = NULL;
|
||||
if (head == NULL)
|
||||
{
|
||||
if (head == NULL) {
|
||||
head = newNode;
|
||||
head->next = head;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
node *current = head;
|
||||
while (current->next != head)
|
||||
{
|
||||
while (current->next != head) {
|
||||
current = current->next;
|
||||
}
|
||||
newNode->next = head;
|
||||
@@ -59,22 +51,17 @@ void cll::insert_front(int new_data)
|
||||
}
|
||||
|
||||
/* List insert a new value at head in list */
|
||||
void cll::insert_tail(int new_data)
|
||||
{
|
||||
void cll::insert_tail(int new_data) {
|
||||
node *newNode;
|
||||
newNode = new node;
|
||||
newNode->data = new_data;
|
||||
newNode->next = NULL;
|
||||
if (head == NULL)
|
||||
{
|
||||
if (head == NULL) {
|
||||
head = newNode;
|
||||
head->next = head;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
node *current = head;
|
||||
while (current->next != head)
|
||||
{
|
||||
while (current->next != head) {
|
||||
current = current->next;
|
||||
}
|
||||
current->next = newNode;
|
||||
@@ -88,18 +75,13 @@ int cll::get_size() { return total; }
|
||||
|
||||
/* Return true if the requested item (sent in as an argument)
|
||||
is in the list, otherwise return false */
|
||||
bool cll::find_item(int item_to_find)
|
||||
{
|
||||
if (head == NULL)
|
||||
{
|
||||
bool cll::find_item(int item_to_find) {
|
||||
if (head == NULL) {
|
||||
cout << "List is empty !" << endl;
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
node *current = head;
|
||||
while (current->next != head)
|
||||
{
|
||||
while (current->next != head) {
|
||||
if (current->data == item_to_find)
|
||||
return true;
|
||||
current = current->next;
|
||||
@@ -113,17 +95,12 @@ int cll::operator*() { return head->data; }
|
||||
|
||||
/* Overload the pre-increment operator.
|
||||
The iterator is advanced to the next node. */
|
||||
void cll::operator++()
|
||||
{
|
||||
if (head == NULL)
|
||||
{
|
||||
void cll::operator++() {
|
||||
if (head == NULL) {
|
||||
cout << "List is empty !" << endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
node *current = head;
|
||||
while (current->next != head)
|
||||
{
|
||||
while (current->next != head) {
|
||||
current = current->next;
|
||||
}
|
||||
current->next = head->next;
|
||||
|
||||
@@ -9,14 +9,12 @@
|
||||
#ifndef CLL_H
|
||||
#define CLL_H
|
||||
/*The data structure is a linear linked list of integers */
|
||||
struct node
|
||||
{
|
||||
struct node {
|
||||
int data;
|
||||
node* next;
|
||||
};
|
||||
|
||||
class cll
|
||||
{
|
||||
class cll {
|
||||
public:
|
||||
cll(); /* Construct without parameter */
|
||||
~cll();
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
#include "cll.h"
|
||||
using namespace std;
|
||||
|
||||
int main()
|
||||
{
|
||||
int main() {
|
||||
/* Test CLL */
|
||||
cout << "----------- Test construct -----------" << endl;
|
||||
cll list1;
|
||||
|
||||
Reference in New Issue
Block a user