-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStrList.h
141 lines (115 loc) · 3.5 KB
/
StrList.h
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#pragma once
#include <stdlib.h>
#define DATA 500
/********************************************************************************
*
* A StrList library.
*
* This library provides a StrList of STRINGS data structure.
*
* This library will fail in unpredictable ways when the system memory runs
* out.
*
********************************************************************************/
/*
* StrList represents a StrList data structure.
*/
#ifndef LIST
#define LIST
struct _StrList;
typedef struct _StrList StrList;
struct _node;
typedef struct _node Node;
#endif
/*
* Allocates a new empty StrList.
* It's the user responsibility to free it with StrList_free.
*/
StrList* StrList_alloc();
Node* Node_alloc(char* data, Node* next);
void Node_free(Node* node);
/*
* Frees the memory and resources allocated to StrList.
* If StrList==NULL does nothing (same as free).
*/
void StrList_free(StrList* StrList);
/*
* Returns the number of elements in the StrList.
*/
void build_list(StrList* StrList);
size_t StrList_size(const StrList* StrList);
/*
* Inserts an element in the end of the StrList.
*/
void StrList_insertLast(StrList* StrList,
const char* data);
/*
* Inserts an element at given index
*/
void StrList_insertAt(StrList* StrList,
const char* data,int index);
/*
* Returns the StrList first data.
*/
char* StrList_firstData(const StrList* StrList);
/*
* Prints the StrList to the standard output.
*/
void StrList_print(const StrList* StrList);
/*
Prints the word at the given index to the standard output.
*/
void StrList_printAt(const StrList* Strlist,int index);
/*
* Return the amount of chars in the list.
*/
int StrList_printLen(const StrList* Strlist);
/*
Given a string, return the number of times it exists in the list.
*/
int StrList_count(StrList* StrList, const char* data);
/*
Given a string and a list, remove all the appearences of this string in the list.
*/
void StrList_remove(StrList* StrList, const char* data);
/*
Given an index and a list, remove the string at that index.
*/
void StrList_removeAt(StrList* StrList, int index);
/*
* Checks if two StrLists have the same elements
* returns 0 if not and any other number if yes
*/
int StrList_isEqual(const StrList* StrList1, const StrList* StrList2);
/*
* Clones the given StrList.
* It's the user responsibility to free it with StrList_free.
*/
StrList* StrList_clone(const StrList* StrList);
/*
* Reverces the given StrList.
*/
void StrList_reverse( StrList* StrList);
/*
* Sort the given list in lexicographical order
*/
void StrList_sort( StrList* StrList);
/*
* Checks if the given list is sorted in lexicographical order
* returns 1 for sorted, 0 otherwise
*/
int StrList_isSorted(StrList* StrList);
/*
* Inserts an element in the first of the StrList.
*/
//////////////////////////////////////////////////
void StrList_insertFirst(StrList* StrList,const char* data);
//compare n'th first chars of two strings
int isEqualStringN(const char s1[], const char s2[], int n);
//return how many times s2 contains s1
int CountSubstring(const char *s1, char *s2);
//Given strings s1 and s2, remove all the appearences of s1 in the s2
//////////////////////////////////////////////////////////////////////////////
void remove_from_string(const char *s1, char*s2);
void delete_list(StrList* StrList);
char* getDynamicString(FILE* fp, size_t size, int length);